evo_lite.s 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479
  1. ;/* Evolution System-Kernal (LITE EDITION!) v2.0d
  2. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  3. * Copyright © 1991-1996 By Trevor Leigh Mensah / Centillion Software.
  4. * All Rights Are Reserved.
  5. *
  6. * This software is provided as-is and is subject to change without notice;
  7. * No warranties are made or implied. All use is entirely at your own risk.
  8. * Absolutely no liability or responsibility is assumed whatsoever.
  9. *
  10. * Provided Kernal functions: (All Program counter relative)
  11. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  12. * _LVOAllocSystem : Operating System friendly takeover functions.
  13. * _LVOFreeSystem : Restore Operating System to its original state.
  14. * _LVOAddIrqServer : Install an interrupt (0-13) handler into cpu vectors
  15. * _LVORemIrqServer : Remove interrupt handlers installed with AddIrqServer
  16. * _LVOSetIrqBits : Set irq control bits (kernel compatible method)
  17. * _LVOClrIrqBits : Clear irq control bits (kernel compatible method)
  18. * _LVOCopperIrqSync : Replacement vblank function, use with clist retrigger
  19. * _LVOGetVBR : Return address of the current cpu vectorbase
  20. * _LVODiskDone : If disk (hardware) is doing a write, pause until done
  21. * _LVONewCopper : Activate a new Copperlist in copper address 1
  22. * _LVONewCopper2 : Activate a new Copperlist in copper address 2
  23. * _LVOBlitDone : Simple hardware wait until blitter is free.
  24. * _LVOSetVolume : Just set volume of all sound channels (not dma)
  25. * _LVOSaveCIA : Save current contents of ciaa/b chip registers
  26. * _LVORestoreCIA : Restore ciaa/b chip registers from copy of originals
  27. * *_LVOAllocCIAB : Allocate either Timer A or Timer B in ciab
  28. * *_LVOSetCIABSpeed : Set Timer Speed for either Timer A or Timer B in ciab
  29. * *_LVOUpdateCIAB : Interrupt call to check Timer A or Timer B in ciab
  30. * *_LVOAllocCIAA : Allocate either Timer A or Timer B in ciaa
  31. * *_LVOSetCIAASpeed : Set Timer Speed for either Timer A or Timer B in ciaa
  32. * *_LVOUpdateCIAA : Interrupt call to check Timer A or Timer B in ciaa
  33. * *_LVOScanConfig : Check for type of custom chips, cpu, kickstart, etc.
  34. * *_LVOSoftReset : OS friendly enforced system reboot.
  35. * *_LVOSetCaches : OS friendy setting of caches (via _LVOCacheControl)
  36. * *_LVOClearCaches : OS friendy flush of caches (via _LVOCacheClearU)
  37. * *_LVOFindAssign : Does file exist? (supresses insert disk requesters)
  38. * *_LVOLoadDosFile : Load file (OS mounted device) into any address.
  39. * *_LVOSaveDosFile : Save file (OS mounted device) from any address.
  40. * *_LVOLockDisk : Wait for user to insert a disk/device (OS friendly)
  41. * *_LVOLockFile : Attempt to lock a file on any device (OS friendly)
  42. * *_LVOHunkRelocate : Relocate dos format executable file into raw code.
  43. * *_LVOHunkLength : Calculate the memory required for a relocated file
  44. *
  45. */
  46. section lite_engine,code
  47. include 'sys:evo_lite_2.0c.i'
  48. Begin: bsr.w _LVOAllocSystem * Take Over System..
  49. beq.s exit_now
  50. lea readkb(pc),a0 * Add Keyboard Interrupt
  51. moveq #INTB_PORTS,d0
  52. bsr.w _LVOAddIrqServer
  53. ;/* MainVBL()
  54. *
  55. */
  56. ; bsr ActivateSystem
  57. MainVBL: btst #CIAB_GAMEPORT0,_ciaa * Left Mouse?
  58. beq.s .exit_vbl
  59. move.b Key(pc),d0
  60. cmp.b #esc,d0 * Escape Key?
  61. bne.s MainVBL
  62. .exit_vbl
  63. ; bsr DeactivateSystem
  64. bsr.w _LVOFreeSystem * Restore the System..
  65. exit_now: rts
  66. cnop 0,4
  67. readkb: lea KeyMatrix(pc),a0
  68. bsr.w _LVOGetKeys
  69. rts
  70. ;/* AllocSystem() v2.0d (SAFE-MODE VERSION)
  71. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  72. * Copyright © 1991-1996 By Trevor Leigh Mensah / Centillion Software.
  73. * All Rights Are Reserved.
  74. *
  75. * $Notes:
  76. * ¯¯¯¯¯¯¯
  77. * This is a full system takeover that tries to be as safe as it possibly can
  78. * considering there is no 'official' way of taking over the amiga`s custom
  79. * hardware. First it attempts to allocate as much as it can from the system
  80. * (this includes the 'serial port', 'parallel port' and 'audio channels')
  81. * doing this addes an extra margin of saftey since now we wont start if the
  82. * user was say printing, accessing parnet or downloading on a modem, etc.
  83. * Taking over with these activies going on could make us crash on re-entry.
  84. *
  85. * Eventually we disables multitasking and preserve the state of custom chip
  86. * hardware registers and complex interface adaptors (was tricky!). Once this
  87. * is complete a full installation of all 14 interrupts is done. Also null
  88. * exception handlers are installed to prevent gurus. Your code should return
  89. * back to the OS (safely) without any crash and with everything intact. No
  90. * dissassembler / tracer / monitor functions are in the LITE version.
  91. *
  92. * Once takeover has occured the OS will be completely HALTED. All interrupts
  93. * and custom hardware will be in use by our system. We have complete access
  94. * to ALL the hardware and the total control of the machine at our disposal.
  95. * All interrupts are running under our software. To allocate an interrupt you
  96. * must use the provided 'AddIrqServer' function as this automatically handles
  97. * all 14 multiplexed interrupts so you can specify any amiga interrupt to
  98. * install. eg. ports interrupt, blitter queue interrupt, and so on. Note we
  99. * are running at the lowest level possible (bashing at the bare metal) with
  100. * no system interaction whatsoever so no use of any of the amiga operating
  101. * system functions are allowed other than those provided through our kernal
  102. * (such as device loading/saving) etc.
  103. *
  104. * $Takeover Steps:
  105. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  106. * Firstly in AllocSystem() we;
  107. *
  108. * 01.System friendly opening of used libraries, dos, graphics, etc.
  109. * 02.System friendly allocation of audio channels and hardware..
  110. * 03.System friendly allocation of serial port & registers hardware..
  111. * 04.System friendly allocation of parallel port & registers hardware..
  112. * 05.System friendly reset of sprite-res (as _LVOLoadView is bugged)..
  113. * 06.System friendly load view to create a 'null view' - zero aga+ registers
  114. * 07.System friendly setting of our task to highest priority..
  115. * 08.System friendly disabling of operating system requesters..
  116. *
  117. * Now in the Shared Part, DeactivateSystem() we ;
  118. *
  119. * 09.System friendly allocation of blitter hardware..
  120. * 10.System friendly disable of multitasking..
  121. * 11.System friendly call to Supervisor - I am the Law!
  122. * 12.Wait for hardware custom register disk dma to finish..
  123. * 13.Wait for hardware custom register blit dma to finish..
  124. * 14.Preserve hardware custom register status of dmacon..
  125. * 15.Preserve hardware custom register status of intreq..
  126. * 16.Preserve hardware custom register status of intena..
  127. * 17.Preserve hardware custom register status of adkcon..
  128. * 18.Preserve hardware custom register status of ciaa hardware..
  129. * 19.Preserve hardware custom register status of ciab hardware..
  130. * 20.Preserve entire vectorbase include old cpu interrupts & traps..
  131. * 21.Install our custom irq/trap/exception handlers
  132. *
  133. * And finally from AllocSystem();
  134. *
  135. * 22.Install null copperlist views.
  136. *
  137. * then Return..
  138. */
  139. Version: dc.b "$VER: Evolution System Kernal v2.0d (Lite Edition)",$a
  140. dc.b "Copyright © 1991-1996 By Trevor Leigh Mensah.",$a
  141. dc.b "All Rights Reserved.",0
  142. cnop 0,4
  143. VecList: dc.w SimpleRevive-VecList * $08 (Bus Error)
  144. dc.w SimpleRevive-VecList * $0C (Address Error)
  145. dc.w SimpleRevive-VecList * $10 (Illega Instruction)
  146. dc.w SimpleRevive-VecList * $14 (Divide by Zero)
  147. dc.w SimpleRevive-VecList * $18 (CHK Exception)
  148. dc.w SimpleRevive-VecList * $1C (TRAPV Error)
  149. dc.w SimpleRevive-VecList * $20 (Privilege Violation)
  150. dc.w SimpleRevive-VecList * $24 (Trace Exception)
  151. dc.w SimpleRevive-VecList * $28 (Axxx inst Emulation)
  152. dc.w SimpleRevive-VecList * $2C (Fxxx inst Emulation)
  153. dc.w SimpleRevive-VecList * $30 (Unassigned)
  154. dc.w SimpleRevive-VecList * $34 (CP-Protocol Violation)
  155. dc.w SimpleRevive-VecList * $38 (Format Error)
  156. dc.w SimpleRevive-VecList * $3C (Uninitialised irq)
  157. dc.w SimpleRevive-VecList * $40 (Unassigned, Reserved)
  158. dc.w SimpleRevive-VecList * $44 (Unassigned, Reserved)
  159. dc.w SimpleRevive-VecList * $48 (Unassigned, Reserved)
  160. dc.w SimpleRevive-VecList * $4C (Unassigned, Reserved)
  161. dc.w SimpleRevive-VecList * $50 (Unassigned, Reserved)
  162. dc.w SimpleRevive-VecList * $54 (Unassigned, Reserved)
  163. dc.w SimpleRevive-VecList * $58 (Unassigned, Reserved)
  164. dc.w SimpleRevive-VecList * $5C (Unassigned, Reserved)
  165. dc.w SimpleRevive-VecList * $60 (Spurious Interrupt)
  166. dc.w Level1_IRQ-VecList * $64 (Level 1 Interrupt)
  167. dc.w Level2_IRQ-VecList * $68 (Level 2 Interrupt)
  168. dc.w Level3_IRQ-VecList * $6C (Level 3 Interrupt)
  169. dc.w Level4_IRQ-VecList * $70 (Level 4 Interrupt)
  170. dc.w Level5_IRQ-VecList * $74 (Level 5 Interrupt)
  171. dc.w Level6_IRQ-VecList * $78 (Level 6 Interrupt)
  172. dc.w Level7_IRQ-VecList * $7C (Level 7 Interrupt)
  173. dc.w NullVec-VecList * $80 (Trap 00 Ptr -TRAP #0)
  174. dc.w NullVec-VecList * $84 (Trap 01 Ptr -TRAP #1)
  175. dc.w NullVec-VecList * $88 (Trap 02 Ptr -TRAP #2)
  176. dc.w NullVec-VecList * $8C (Trap 03 Ptr -TRAP #3)
  177. dc.w NullVec-VecList * $90 (Trap 04 Ptr -TRAP #4)
  178. dc.w NullVec-VecList * $94 (Trap 05 Ptr -TRAP #5)
  179. dc.w NullVec-VecList * $98 (Trap 06 Ptr -TRAP #6)
  180. dc.w NullVec-VecList * $9C (Trap 07 Ptr -TRAP #7)
  181. dc.w NullVec-VecList * $A0 (Trap 08 Ptr -TRAP #8)
  182. dc.w NullVec-VecList * $A4 (Trap 09 Ptr -TRAP #9)
  183. dc.w NullVec-VecList * $A8 (Trap 10 Ptr -TRAP #10)
  184. dc.w NullVec-VecList * $AC (Trap 11 Ptr -TRAP #11)
  185. dc.w NullVec-VecList * $B0 (Trap 12 Ptr -TRAP #12)
  186. dc.w NullVec-VecList * $B4 (Trap 13 Ptr -TRAP #13)
  187. dc.w NullVec-VecList * $B8 (Trap 14 Ptr -TRAP #14)
  188. dc.w NullVec-VecList * $BC (Trap 15 Ptr -TRAP #15)
  189. dc.w NullVec-VecList * $C0 (FPCP Bra/Set Unordered Condition)
  190. dc.w NullVec-VecList * $C4 (FPCP Inexact Result)
  191. dc.w NullVec-VecList * $C8 (FPCP Divide by Zero)
  192. dc.w NullVec-VecList * $CC (FPCP Underflow)
  193. dc.w NullVec-VecList * $D0 (FPCP Operand Error)
  194. dc.w NullVec-VecList * $D4 (FPCP Signalling Not-A-Number)
  195. dc.w NullVec-VecList * $D8 (Unassigned, Reserved)
  196. dc.w NullVec-VecList * $DC (PMMU Configuration Error)
  197. dc.w NullVec-VecList * $E0 (PMMU Illegal Operation)
  198. dc.w NullVec-VecList * $E4 (PMMU Illegal Operation)
  199. dc.w NullVec-VecList * $E8 (PMMU Access Level Violation)
  200. dc.w NullVec-VecList * $EC (Unassigned, Reserved)
  201. dc.w NullVec-VecList * $F0 (Unassigned, Reserved)
  202. dc.w NullVec-VecList * $F4 (Unassigned, Reserved)
  203. dc.w NullVec-VecList * $F8 (Unassigned, Reserved)
  204. dc.w NullVec-VecList * $FC (Unassigned, Reserved)
  205. dc.w -1 * End of Vector Table
  206. cnop 0,4
  207. _LVOAllocSystem:
  208. movem.l d1-a6,-(sp)
  209. lea error(pc),a0
  210. sf.b (a0) * an error as default
  211. *-------------- Open dos library..
  212. move.l (AbsExecBase).w,a6 * get execbase
  213. lea DosName(pc),a1
  214. jsr _LVOOldOpenLibrary(a6)
  215. tst.l d0 * did dos fail?
  216. beq.w Close_Libs
  217. lea _DOSBase(pc),a0
  218. move.l d0,(a0) * save dosbase
  219. *-------------- Open intuition library..
  220. lea IntName(pc),a1
  221. jsr _LVOOldOpenLibrary(a6)
  222. tst.l d0 * did intuition fail?
  223. beq.w Close_Libs
  224. lea _IntuitionBase(pc),a0
  225. move.l d0,(a0) * save dosbase
  226. *-------------- Open graphics library..
  227. lea GfxName(pc),a1
  228. jsr _LVOOldOpenLibrary(a6)
  229. tst.l d0 * did graphics fail?
  230. beq.w Close_Libs
  231. lea _GfxBase(pc),a0
  232. move.l d0,(a0) * save dosbase
  233. bsr.w _GetVBR * get current vectorbase addr
  234. *-------------- Find address of our task..
  235. suba.l a1,a1 * find *our* task
  236. jsr _LVOFindTask(a6) * get it..
  237. tst.l d0 * got our task correctly?
  238. beq.w Close_Libs
  239. lea our_task(pc),a0
  240. move.l d0,(a0) * save task address
  241. *-------------- Allocate audio hardware..
  242. lea aud_chanmap(pc),a0
  243. lea channel_map(pc),a1
  244. move.l a1,(a0)
  245. lea aud_messageport(pc),a1
  246. move.l a1,aud_msgport-aud_chanmap(a0)
  247. sf.b audio_alloc-aud_chanmap(a0) * default is `not_allocated'
  248. *-------------- Allocate an audio signal bit..
  249. moveq #-1,d0
  250. jsr _LVOAllocSignal(a6) * allocate a signal bit...
  251. tst.b d0 * did we get a signal?
  252. bmi.w aud_noalloc * no! we didn`t get one!
  253. lea aud_signal(pc),a0
  254. move.b d0,(a0) * save into audio struct..
  255. *-------------- Now create audio port..
  256. lea aud_messageport(pc),a1
  257. jsr _LVOAddPort(a6) * now try to create audio port
  258. tst.l d0
  259. beq.w noport * error creating audio port?
  260. *-------------- Open audio device..
  261. moveq #0,d0
  262. move.l d0,d1
  263. lea audn(pc),a0
  264. lea aud_ioreq(pc),a1
  265. jsr _LVOOpenDevice(a6) * try to open audio.device..
  266. tst.l d0
  267. bne.w nodev
  268. lea audio_alloc(pc),a0
  269. st.b (a0) * set audio as 'allocated'
  270. *-------------- Open the misc resource..
  271. move.l (AbsExecBase).w,a6 * Prepare to use exec
  272. lea MiscName(pc),a1
  273. jsr _LVOOpenResource(a6) * Open "misc.resource"
  274. tst.l d0
  275. beq.w misc_failed
  276. lea _MiscBase(pc),a0
  277. move.l d0,(a0)
  278. move.l d0,a6
  279. *-------------- Allocate serial control bits (DTR,CTS, etc.)
  280. moveq #MR_SERIALBITS,d0 * We want these bits
  281. lea SerName(pc),a1 * This is our name
  282. jsr MR_ALLOCMISCRESOURCE(a6)
  283. tst.l d0
  284. bne.w no_serial_bits * Someone else has it...
  285. *-------------- Allocate serial port registers & interrupts
  286. moveq #MR_SERIALPORT,d0
  287. lea SerName(pc),a1
  288. jsr MR_ALLOCMISCRESOURCE(a6)
  289. tst.l d0
  290. bne.w no_serial_port * Someone else has it...
  291. *-------------- Allocate parallel bits & interrupts (BUSY,ACK,etc.)
  292. moveq #MR_PARALLELBITS,d0 * We want these bits
  293. lea ParName(pc),a1 * This is our name
  294. jsr MR_ALLOCMISCRESOURCE(a6)
  295. tst.l d0
  296. bne.w no_parallel_bits * Someone else has it...
  297. *-------------- Allocate 8 bit parallel data port (CIAAPRA & CIAADDRA only!)
  298. moveq #MR_PARALLELPORT,d0
  299. lea ParName(pc),a1
  300. jsr MR_ALLOCMISCRESOURCE(a6)
  301. tst.l d0
  302. bne.w no_parallel_port * Someone else has it...
  303. *-------------- Give our task maximum cpu priority..
  304. move.l d0,a1 * a1.l = our task address..
  305. moveq #127,d0 * MAXIMUM priority please!
  306. move.l (AbsExecBase).w,a6
  307. jsr _LVOSetTaskPri(a6) * set it..
  308. lea old_taskpri(pc),a0
  309. move.l d0,(a0) * save our old priority...
  310. *-------------- Disable operating system requesters..
  311. lea old_WindowPtr(pc),a0
  312. move.l our_task(pc),a1 * our task address
  313. move.l pr_WindowPtr(a1),(a0) * save old window ptr..
  314. moveq #-1,d0 * No Requestors allowed..
  315. move.l d0,pr_WindowPtr(a1) * Disable OS Requesters now!
  316. *-------------- Flushes graphics hardware to basic state (according to system).
  317. lea wbscreen(pc),a0
  318. clr.l (a0)
  319. *-------------- Are we running on Kickstart V39 + (if so reset sprite`s)
  320. move.w LIB_VERSION(a6),d0 * get operating system version
  321. cmp.w #39,d0 * if <39 we don`t have to flush
  322. bcs.b not_ks3 * sprite res to fix an os bug!
  323. *-------------- Lock workbench screen & reset sprite resolution`s..
  324. move.l #$80000032,taglist-wbscreen(a0)
  325. clr.l res-wbscreen(a0)
  326. move.l _IntuitionBase(pc),a6
  327. lea wbn(pc),a0
  328. move.l our_task(pc),a1
  329. jsr _LVOLockPubScreen(a6)
  330. tst.l d0
  331. beq.s not_ks3
  332. lea wbscreen(pc),a0
  333. move.l d0,(a0)
  334. move.l d0,a0
  335. move.l 48(a0),a0
  336. lea taglist(pc),a1
  337. move.l _GfxBase(pc),a6
  338. jsr _LVOVideoControl(a6)
  339. lea oldres(pc),a0
  340. move.l res-oldres(a0),(a0)
  341. move.l #$80000031,taglist-oldres(a0)
  342. move.l #1,res-oldres(a0)
  343. move.l wbscreen(pc),a0
  344. move.l 48(a0),a0
  345. lea taglist(pc),a1
  346. jsr _LVOVideoControl(a6)
  347. *-------------- Force system to refresh screen()
  348. move.l wbscreen(pc),a0
  349. move.l _IntuitionBase(pc),a6
  350. jsr _LVOMakeScreen(a6)
  351. jsr _LVORethinkDisplay(a6)
  352. *-------------- Wait for 2 top of frames (2 incase of laceframe)
  353. move.l _GfxBase(pc),a6
  354. jsr _LVOWaitTOF(a6)
  355. jsr _LVOWaitTOF(a6)
  356. *-------------- Hardware sprites are now at 140ns!
  357. not_ks3
  358. *-------------- Load a 'null' view to reset remaining hardware registers...
  359. move.l _GfxBase(pc),a6
  360. lea sysview(pc),a1
  361. move.l gb_ActiView(a6),(a1)
  362. suba.l a1,a1
  363. jsr _LVOLoadView(a6)
  364. jsr _LVOWaitTOF(a6)
  365. jsr _LVOWaitTOF(a6)
  366. *-------------- Call SHARED Take over functions; DeactivaeSystem()
  367. bsr DeactivateSystem
  368. *-------------- Install `nullview' copperlist into BOTH copperlist pointers..
  369. lea nullcopper(pc),a1
  370. bsr.w _LVONewCopper
  371. bsr.w _LVONewCopper2
  372. *-------------- Now reset audio channel`s
  373. moveq #0,d0 * no volume..
  374. bsr.w _LVOSetVolume
  375. move.w #$444,color(a0) * paper dark-grey (default)
  376. lea error(pc),a0
  377. st.b (a0) * no error occured
  378. movem.l (sp)+,d1-a6
  379. moveq #0,d0
  380. move.b error(pc),d0 * error occured?
  381. rts
  382. ;/* DeactivateSystem()
  383. * ------------------
  384. * Shared Part:
  385. *
  386. * 01.System friendly allocation of blitter hardware..
  387. * 02.System friendly disable of multitasking..
  388. * 03.System friendly call to Supervisor - I am the Law!
  389. * 04.Wait for hardware custom register disk dma to finish..
  390. * 05.Wait for hardware custom register blit dma to finish..
  391. * 06.Preserve hardware custom register status of dmacon..
  392. * 07.Preserve hardware custom register status of intreq..
  393. * 08.Preserve hardware custom register status of intena..
  394. * 09.Preserve hardware custom register status of adkcon..
  395. * 10.Preserve hardware custom register status of ciaa hardware..
  396. * 11.Preserve hardware custom register status of ciab hardware..
  397. * 12.Preserve entire vectorbase include old cpu interrupts & traps..
  398. * 13.Install our custom irq/trap/exception handlers
  399. */
  400. DeactivateSystem
  401. *-------------- Allocate the blitter from the system...
  402. move.l _GfxBase(pc),a6
  403. jsr _LVOOwnBlitter(a6)
  404. jsr _LVOWaitBlit(a6)
  405. jsr _LVOWaitBlit(a6)
  406. *-------------- Turn off multitasking capabilities..
  407. move.l (AbsExecBase).w,a6 * disable multitasking
  408. jsr _LVOForbid(a6)
  409. *-------------- Go into full supervisor mode now.. I AM THE LAW!
  410. jsr _LVOSuperState(a6) * Go to supervisor mode
  411. lea oldsysstack(pc),a0
  412. move.l d0,(a0) * save old system stackptr
  413. *-------------- Make sure a disk read/write isn`t too dangerous..
  414. bsr.w _LVODiskDone
  415. *-------------- Wait for blitter (hardware method - for ultra saftey)...
  416. bsr.w _LVOBlitDone
  417. *-------------- Restore/set dma control,interrupts,requests, audio,uart,etc
  418. bsr.w SaveCustom
  419. *-------------- Freeze all dma and interrupts..
  420. bsr.w StopCustom
  421. *-------------- Save CIAA Hardware Range
  422. lea _ciaa,a0
  423. lea ciaa_store(pc),a1
  424. bsr.w _LVOSaveCIA
  425. *-------------- Save CIAB Hardware Range
  426. lea _ciab,a0
  427. lea ciab_store(pc),a1
  428. bsr.w _LVOSaveCIA
  429. *-------------- Save old vectors & interrupts...
  430. lea VecStore(pc),a1 ;ptr to vector storage
  431. move.l _VBR(pc),a0
  432. moveq #62-1,d0 ;no. of vectors to save
  433. _SaveVec: move.l (a0)+,(a1)+ ;save vector ptr
  434. dbra d0,_SaveVec ;save until all 40 done
  435. *-------------- Install null interrupts..
  436. lea VecList(pc),a0 ;get vectorbase ptr
  437. move.l a0,a2 ;a2=vectorbase
  438. move.l _VBR(pc),a1
  439. addq.l #8,a1 ;ptr $8(a1) in memory
  440. .next_entry: moveq #0,d0 ;erase d0
  441. move.w (a2)+,d0 ;get entry from table
  442. cmp.w #-1,d0 ;reached end of table?
  443. beq.s .table_done ;if so were done!
  444. add.l a0,d0 ;fix (relocate) ptr
  445. move.l d0,(a1)+ ;save into vectorbase
  446. bra.s .next_entry
  447. .table_done:
  448. bsr SetCurrIntena * set current intena
  449. rts
  450. ;/* _LVOFreeSystem()
  451. * ----------------
  452. * This function restore the operating system back to normal. Its original
  453. * screen will be re-installed and multitasking operational.
  454. *
  455. * First we ActivateSystem();
  456. *
  457. * 1. Wait for blitter to finish.
  458. * 2. Disable all interrupt activities.
  459. * 3. Restore system ciaa & ciab settings.
  460. * 4. Restore system interrupts and vectorbase.
  461. * 5. Restore system dma, intena, intreq and adkcon.
  462. * 6. Back into userstate (for multitasking)
  463. * 7. Permit Multitasking (multitasking now reactivated)
  464. * 8. Give the blitter back to the system.
  465. *
  466. * And finally the FreeSystem() Part;
  467. *
  468. * 9. Restore Sprite Resolution to that of the Workbench (if >= KS39)
  469. * 10.Restore Old Workbench view (screen)
  470. * 11.Give Audio channels back to the system. (if allocated)
  471. * 12.Give Parallel Port & Registers back to the system. (if allocated)
  472. * 13.Give Serial Port & Registers back to the system. (if allocated)
  473. * 14.Restore our task priority to normality. (from highest possible)
  474. * 15.Close all opened libraries.
  475. *
  476. * Now ready to exit back to system.
  477. */
  478. cnop 0,4
  479. _LVOFreeSystem: movem.l d1-a6,-(sp)
  480. bsr ActivateSystem * partially revive system
  481. * but not its display or audio
  482. *-------------- restore graphics hardware to original status..
  483. move.l wbscreen(pc),d0
  484. beq.s exit2
  485. move.l d0,a0
  486. lea res(pc),a1
  487. move.l oldres(pc),(a1)
  488. lea taglist(pc),a1
  489. move.l 48(a0),a0
  490. move.l _GfxBase(pc),a6
  491. jsr _LVOVideoControl(a6)
  492. move.l _IntuitionBase(pc),a6
  493. move.l wbscreen(pc),a0
  494. jsr _LVOMakeScreen(a6)
  495. move.l wbscreen(pc),a1
  496. sub.l a0,a0
  497. jsr _LVOUnlockPubScreen(a6)
  498. *-------------- restore system`s old copperlist display views..
  499. exit2 move.l _GfxBase(pc),a6
  500. move.l sysview(pc),a1
  501. jsr _LVOLoadView(a6)
  502. jsr _LVOWaitTOF(a6)
  503. jsr _LVOWaitTOF(a6)
  504. move.l gb_copinit(a6),_custom+cop1lc
  505. move.l _IntuitionBase(pc),a6
  506. jsr _LVORethinkDisplay(a6)
  507. *-------------- restore our system task priority to its original state..
  508. move.l our_task(pc),a1
  509. move.l old_taskpri(pc),d0
  510. move.l (AbsExecBase).w,a6
  511. jsr _LVOSetTaskPri(a6)
  512. *-------------- free parallel port...
  513. free_parallel_port
  514. moveq #MR_PARALLELPORT,d0
  515. move.l _MiscBase(pc),a6
  516. jsr MR_FREEMISCRESOURCE(a6)
  517. *-------------- free parallel registers...
  518. no_parallel_port:
  519. moveq #MR_PARALLELBITS,d0
  520. move.l _MiscBase(pc),a6
  521. jsr MR_FREEMISCRESOURCE(a6)
  522. *-------------- free serial port.
  523. no_parallel_bits:
  524. moveq #MR_SERIALPORT,d0
  525. move.l _MiscBase(pc),a6
  526. jsr MR_FREEMISCRESOURCE(a6)
  527. *-------------- free serial registers..
  528. no_serial_port: moveq #MR_SERIALBITS,d0
  529. move.l _MiscBase(pc),a6
  530. jsr MR_FREEMISCRESOURCE(a6)
  531. no_serial_bits:
  532. misc_failed:
  533. *-------------- now deallocate() audio hardware..
  534. FreeAudio: move.b audio_alloc(pc),d0
  535. beq.s aud_noalloc
  536. *-------------- now reset audio channel`s
  537. moveq #0,d0
  538. bsr _LVOSetVolume
  539. *-------------- close audio device..
  540. move.b audio_alloc(pc),d0
  541. lea aud_ioreq(pc),a1
  542. move.l (AbsExecBase).w,a6
  543. jsr _LVOCloseDevice(a6)
  544. *-------------- free audio message port
  545. nodev lea aud_messageport(pc),a1
  546. move.l (AbsExecBase).w,a6
  547. jsr _LVORemPort(a6)
  548. *-------------- free audio signal
  549. noport moveq #0,d0
  550. move.b aud_signal(pc),d0
  551. move.l (AbsExecBase).w,a6
  552. jsr _LVOFreeSignal(a6)
  553. aud_noalloc
  554. *-------------- Re-enable Operating System requesters..
  555. move.l our_task(pc),a1
  556. move.l old_WindowPtr(pc),pr_WindowPtr(a1)
  557. *-------------- Close graphics library..
  558. Close_Libs: move.l _GfxBase(pc),d0
  559. beq.s closeint
  560. move.l d0,a1
  561. move.l (AbsExecBase).w,a6
  562. jsr _LVOCloseLibrary(a6)
  563. *-------------- Close intuition library..
  564. closeint move.l _IntuitionBase(pc),d0
  565. beq.s closedos
  566. move.l d0,a1
  567. move.l (AbsExecBase).w,a6
  568. jsr _LVOCloseLibrary(a6)
  569. *-------------- Close dos library..
  570. closedos: move.l _DOSBase(pc),d0
  571. beq.s exitfast
  572. move.l d0,a1
  573. move.l (AbsExecBase).w,a6
  574. jsr _LVOCloseLibrary(a6)
  575. *-------------- no command line return code for us..
  576. exitfast: movem.l (sp)+,d1-a6
  577. moveq #0,d0
  578. rts
  579. ;/* ActivateSystem
  580. * --------------
  581. * Shared part: This function will re-activate the system upto the point
  582. * where AmigaDOS is functional and able to grant us access to load / save
  583. * files. This system function will not restore the operating system display.
  584. * To do this a full restoration is required. Operating system requesters
  585. * are still suppressed in this mode so they will not interfere. This is
  586. * to prevent any 'please insert volume', requesters on the WB, etc.
  587. *
  588. * 1. Wait for blitter to finish.
  589. * 2. Disable all interrupt activities.
  590. * 3. Restore system ciaa & ciab settings.
  591. * 4. Restore system interrupts and vectorbase.
  592. * 5. Restore system dma, intena, intreq and adkcon.
  593. * 6. Back into userstate (for multitasking)
  594. * 7. Permit Multitasking (multitasking now reactivated)
  595. * 8. Give the blitter back to the system.
  596. */
  597. ActivateSystem:
  598. *-------------- Wait until Blitter finished..
  599. bsr.w _LVOBlitDone
  600. *-------------- Turn off all Interrupts and dma, etc.
  601. bsr.w StopCustom
  602. *-------------- Restore CIAA Hardware Range..
  603. lea _ciaa,a0
  604. lea ciaa_store(pc),a1
  605. bsr.w _LVORestoreCIA
  606. *-------------- Restore CIAB Hardware Range
  607. lea _ciab,a0
  608. lea ciab_store(pc),a1
  609. bsr.w _LVORestoreCIA
  610. *-------------- now restore old interrupts & vectors..
  611. lea VecStore(pc),a1 ;ptr to vector storage
  612. move.l _VBR(pc),a2 ;Get VBR Offset in memory
  613. moveq #62/2-1,d0 ;no. of vecs to restore
  614. _RestoreVec: move.l (a1)+,(a2)+ ;restore one vector ptr
  615. move.l (a1)+,(a2)+ ;restore one vector ptr
  616. dbra d0,_RestoreVec ;restore until all done
  617. *-------------- restore/set dma control,interrupts,requests, audio,uart,etc
  618. bsr.w SaveCustom
  619. *-------------- back into userstate()... OS gets control once more..
  620. move.l (AbsExecBase).w,a6
  621. move.l oldsysstack(pc),d0
  622. beq.s .not_in_user
  623. jsr _LVOUserState(a6)
  624. lea oldsysstack(pc),a0
  625. clr.l (a0) * kill old sys stack addr
  626. .not_in_user:
  627. *-------------- re-enable multitasking()... Hold you breath...
  628. jsr _LVOPermit(a6)
  629. *-------------- give the blitter back to the system...
  630. move.l _GfxBase(pc),a6
  631. jsr _LVOWaitBlit(a6)
  632. jsr _LVOWaitBlit(a6)
  633. jmp _LVODisownBlitter(a6)
  634. ;/* GetCPU Vectorbase
  635. * -----------------
  636. */
  637. cnop 0,4
  638. _GetVBR: movem.l d1-a6,-(a7)
  639. move.l (AbsExecBase).w,a6
  640. moveq #15,d7
  641. and.w AttnFlags(a6),d7
  642. beq.s Basic68k
  643. lea PutBase(pc),a5
  644. jsr _LVOSupervisor(a6)
  645. Basic68k: lea _VBR(pc),a5 * ptr to base...
  646. move.l d7,(a5) * save it for later.
  647. move.l d7,d0
  648. BadExec: movem.l (a7)+,d1-a6
  649. rts
  650. cnop 0,4
  651. _LVOGetVBR: move.l _VBR(pc),d0 * return address of current vbr
  652. rts
  653. cnop 0,4
  654. PutBase movec vbr,d7
  655. SimpleRevive:
  656. NullVec: nop * don`t smash 060 pipeline!
  657. rte * exit interrupt/exception
  658. *-------------- disable all dma,interrupts, etc..
  659. cnop 0,4
  660. StopCustom: lea _custom,a0 * custom base in a0..
  661. move.w #All_Off,d0
  662. move.w d0,dmacon(a0)
  663. move.w d0,intena(a0)
  664. move.w d0,intreq(a0)
  665. move.w d0,adkcon(a0)
  666. rts
  667. *-------------- Wait for disk dma to complete..
  668. cnop 0,4
  669. _LVODiskDone: lea _custom,a0 * custom base in a0..
  670. btst #DSKB_DMAON,dskbytr(a0) * Wait disk dma for maximum
  671. beq.s .nodiskdma * certainty
  672. .diskdma: btst #INTB_DSKBLK,intreqr(a0)* DO NOT clear the bit, system
  673. beq.s .diskdma * may be expecting it...
  674. .nodiskdma: rts
  675. *-------------- Wait for blitter to complete..
  676. cnop 0,4
  677. _LVOBlitDone: lea _custom,a0 * custom base in a0..
  678. btst #DMAB_BLTDONE,dmaconr(a0) * bit test twice due to bug
  679. .wblit btst #DMAB_BLTDONE,dmaconr(a0) * in some agnus chip`s.. DOH!
  680. bne.s .wblit
  681. rts
  682. *-------------- Clear volume on all channels..
  683. cnop 0,4
  684. _LVOSetVolume: lea _custom,a0
  685. move.w d0,aud0+ac_vol(a0) * channel 0 audio volume = 0
  686. move.w d0,aud1+ac_vol(a0) * channel 1 audio volume = 0
  687. move.w d0,aud2+ac_vol(a0) * channel 2 audio volume = 0
  688. move.w d0,aud3+ac_vol(a0) * channel 3 audio volume = 0
  689. rts
  690. *-------------- Install Copperlist into copper ptr 1
  691. cnop 0,4
  692. _LVONewCopper: lea _custom,a0 * a6=custom hardware
  693. move.w #DMAF_COPPER,dmacon(a0) * now turn off copper dma
  694. .vb1: btst #0,vposr+1(a0)
  695. beq.s .vb1
  696. .vb2: btst #0,vposr+1(a0)
  697. bne.s .vb2
  698. move.l a1,cop1lc(a0) * install new copperlist ptr
  699. move.w #0,copjmp1(a0) * strobe copper
  700. move.w #Our_Dmacon,dmacon(a0) * copper display..
  701. rts
  702. *-------------- Install Copperlist into copper ptr 2
  703. cnop 0,4
  704. _LVONewCopper2: lea _custom,a0 * a6=custom hardware
  705. move.w #DMAF_COPPER,dmacon(a0) * now turn off copper dma
  706. .vb1: btst #0,vposr+1(a0)
  707. beq.s .vb1
  708. .vb2: btst #0,vposr+1(a0)
  709. bne.s .vb2
  710. move.l a1,cop2lc(a0) * install new copperlist ptr
  711. move.w #0,copjmp2(a0) * strobe copper
  712. move.w #Our_Dmacon,dmacon(a0) * copper display..
  713. rts
  714. *-------------- preserve/set dma control ..
  715. cnop 0,4
  716. SaveCustom: lea _custom,a0
  717. lea old_dmacon(pc),a1
  718. move.w dmaconr(a0),d1
  719. move.w old_dmacon(pc),d0
  720. move.w d1,(a1)
  721. bset #DMAB_SETCLR,d0
  722. andi.w #%1000011111111111,d0
  723. move.w d0,dmacon(a0)
  724. not.w d0
  725. andi.w #%1000011111111111,d0
  726. move.w d0,dmacon(a0)
  727. *-------------- preserve/set interrupt enable ..
  728. move.w intenar(a0),d1
  729. move.w old_intena(pc),d0
  730. move.w d1,old_intena-old_dmacon(a1)
  731. bset #INTB_SETCLR,d0
  732. move.w d0,intena(a0)
  733. not.w d0
  734. move.w d0,intena(a0)
  735. *-------------- preserve/set interrupt requests ..
  736. move.w intreqr(a0),d1
  737. move.w old_intreq(pc),d0
  738. move.w d1,old_intreq-old_dmacon(a1)
  739. bset #INTB_SETCLR,d0
  740. move.w d0,intreq(a0)
  741. not.w d0
  742. move.w d0,intreq(a0)
  743. *-------------- preserve audio, disk, uart control ..
  744. move.w adkconr(a0),d1
  745. move.w old_adkcon(pc),d0
  746. move.w d1,old_adkcon-old_dmacon(a1)
  747. bset #ADKB_SETCLR,d0
  748. move.w d0,adkcon(a0)
  749. not.w d0
  750. move.w d0,adkcon(a0)
  751. rts
  752. ;/* Save_CIA (Preservation for $bfe0001 & $bfd000 cia/cib chips!)
  753. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  754. * The (CIA Timers A & B L/H Bytes) timer registers (two for each timer) have
  755. * different functions depending on whether you reading from or writing to
  756. * them. When you read from the registers, you get the present value of the
  757. * Timer Counter (which counts down from its initial value to zero). When
  758. * you write to these registers, the value is stored in the Timer Latch, and
  759. * from there it can be used to LOAD the Timer Counter using the LOAD bit of
  760. * the CRA or CRB registers (see code below).
  761. *
  762. * Hence the ordering of the A & B Timer save/restoring is important due
  763. * to the Timer Latch. (Caution must be taken if modifying the below routines)
  764. */
  765. cnop 0,4
  766. _LVOSaveCIA: move.b ciacra(a0),_ciacra(a1)
  767. move.b ciacrb(a0),_ciacrb(a1)
  768. bclr #CIACRAB_START,ciacra(a0)
  769. bclr #CIACRBB_START,ciacrb(a0)
  770. bset #CIACRAB_LOAD,ciacra(a0)
  771. bset #CIACRBB_LOAD,ciacrb(a0)
  772. move.b ciatahi(a0),_ciatahi(a1)
  773. move.b ciatalo(a0),_ciatalo(a1)
  774. move.b ciatbhi(a0),_ciatbhi(a1)
  775. move.b ciatblo(a0),_ciatblo(a1)
  776. move.b ciaicr(a0),_ciaicr(a1)
  777. move.b _ciaicr(a1),ciaicr(a0)
  778. move.b ciasdr(a0),_ciasdr(a1)
  779. move.b ciatodhi(a0),_ciatodhi(a1)
  780. move.b ciatodmid(a0),_ciatodmid(a1)
  781. move.b ciatodlow(a0),_ciatodlo(a1)
  782. move.b ciaddrb(a0),_ciaddrb(a1)
  783. move.b ciaddra(a0),_ciaddra(a1)
  784. move.b ciaprb(a0),_ciaprb(a1)
  785. move.b ciapra(a0),_ciapra(a1)
  786. rts
  787. cnop 0,4
  788. _LVORestoreCIA: bclr #CIACRAB_START,ciacra(a0)
  789. bclr #CIACRBB_START,ciacrb(a0)
  790. move.b _ciatahi(a1),ciatahi(a0)
  791. move.b _ciatalo(a1),ciatalo(a0)
  792. move.b _ciatbhi(a1),ciatbhi(a0)
  793. move.b _ciatblo(a1),ciatblo(a0)
  794. move.b _ciacra(a1),ciacra(a0)
  795. move.b _ciacrb(a1),ciacrb(a0)
  796. move.b _ciasdr(a1),ciasdr(a0)
  797. move.b _ciatodhi(a1),ciatodhi(a0)
  798. move.b _ciatodmid(a1),ciatodmid(a0)
  799. move.b _ciatodlo(a1),ciatodlow(a0)
  800. move.b _ciaddrb(a1),ciaddrb(a0)
  801. move.b _ciaddra(a1),ciaddra(a0)
  802. move.b _ciaprb(a1),ciaprb(a0)
  803. move.b _ciapra(a1),ciapra(a0)
  804. bset #CIACRAB_START,ciacra(a0)
  805. bset #CIACRBB_START,ciacrb(a0)
  806. move.b _ciaicr(a1),ciaicr(a0)
  807. rts
  808. Our_Dmacon = %1000001111110000
  809. * | ||||||
  810. * | |||||| AUD0EN Audio channel 0 Enable
  811. * | |||||| AUD1EN Audio channel 1 Enable
  812. * | |||||| AUD2EN Audio channel 2 Enable
  813. * | |||||| AUD3EN Audio channel 3 Enable
  814. * | |||||+----- DSKEN Disk DMA Enable
  815. * | ||||+------ SPREN Sprite DMA Enable
  816. * | |||+------- BLTEN Blitter DMA Enable
  817. * | ||+-------- COPEN Copper DMA Enable
  818. * | |+--------- BPLEN Bitplane DMA Enable
  819. * | +---------- DMAEN Enable all DMA below
  820. * | BLTPRI Blitter DMA Priority (1=blit nasty)
  821. * | BZERO Blitter Logic Zero status bit
  822. * | BBUSY Blitter Busy status byte
  823. * +---------------- SET/CLR control bit
  824. All_Off = %0111111111111111 * all other bits on..
  825. * |
  826. * +---------------- SET/CLR control bit
  827. cnop 0,4
  828. _LVORemIrqServer:
  829. lea irqtab(pc),a1 * ptr to irq table..
  830. moveq #0,d1 * erase d1
  831. move.w d0,d2 * copy of irq
  832. add.w d2,d2 * x2 (68k Compatible)
  833. move.w (a1,d2.w),d1 * get offset
  834. add.l d1,a1 * a1= adr irq jmpptr
  835. clr.l (a1) * clear new jmp ptr
  836. bsr.s _LVOClrIrqBit
  837. rts
  838. cnop 0,4
  839. _LVOClrIrqBit: move.w #All_Off,_custom+intena * disable all irq`s
  840. lea ourint(pc),a1 * ptr to our int bits..
  841. moveq #0,d1 * erase d1
  842. move.w (a1),d1 * get active irqs
  843. bclr d0,d1 * set this irq`s bit
  844. or.w #INTF_SETCLR!INTF_INTEN,d1 * make sure set/clr on!
  845. move.w d1,(a1) * save current irq bits
  846. move.w d1,_custom+intena * enable required irq`s
  847. rts
  848. cnop 0,4
  849. _LVOAddIrqServer:
  850. cmp.w #15,d0 * if >15.. invalid irq
  851. bgt.s invalid_irq
  852. lea irqtab(pc),a1 * ptr to irq table..
  853. moveq #0,d1 * erase d1
  854. move.w d0,d2 * copy of irq into d2
  855. add.w d2,d2 * x2 (68k compatible)
  856. move.w (a1,d2.w),d1 * get offset (not 020)
  857. add.l d1,a1 * a1= adr irq jmpptr
  858. move.l a0,(a1) * set new jmp ptr
  859. bsr.s _LVOSetIrqBit
  860. invalid_irq: rts
  861. cnop 0,4
  862. _LVOSetIrqBit: move.w #All_Off,_custom+intena * disable all irq`s
  863. lea ourint(pc),a1 * ptr to our int bits..
  864. moveq #0,d1 * erase d1
  865. or.w (a1),d1 * get active irqs
  866. bset d0,d1 * set this irq`s bit
  867. or.w #INTF_SETCLR!INTF_INTEN,d1 * make sure set/clr on!
  868. move.w d1,(a1) * save current irq bits
  869. move.w d1,_custom+intena * enable required irq`s
  870. rts
  871. SetCurrIntena: move.w #All_Off,_custom+intena * disable all irq`s
  872. move.w ourint(pc),d1 * get active irqs
  873. ori.w #INTF_SETCLR!INTF_INTEN,d1 * make sure set/clr on!
  874. move.w d1,_custom+intena * enable required irq`s
  875. rts
  876. ;/* Level 1: Transmit Buffer Empty (IRQ 0)
  877. * -------------------------------------
  878. */
  879. cnop 0,4
  880. Level1_IRQ: movem.l d0-a6,-(sp)
  881. move.w _custom+intreqr,d0
  882. btst #INTB_TBE,d0
  883. beq.s .not_tbe
  884. move.l irq0jmp(pc),d0
  885. beq.s .nojmp0
  886. move.l d0,a0
  887. jsr (a0) * call codehook
  888. .nojmp0
  889. move.w #INTF_TBE,_custom+intreq
  890. movem.l (sp)+,d0-a6
  891. nop * dont smash the
  892. rte * 040/060 pipelines!
  893. ;/* Level 1: Disk Block (IRQ 1)
  894. * ---------------------------
  895. */
  896. cnop 0,4
  897. .not_tbe: btst #INTB_DSKBLK,d0
  898. beq.s .not_dskblk
  899. move.l irq1jmp(pc),d0
  900. beq.s .nojmp1
  901. move.l d0,a0
  902. jsr (a0) * call codehook
  903. .nojmp1
  904. move.w #INTF_DSKBLK,_custom+intreq
  905. movem.l (sp)+,d0-a6
  906. nop * dont smash the
  907. rte * 040/060 pipelines!
  908. ;/* Level 1: Soft Interrupt (IRQ 2)
  909. * -------------------------------
  910. */
  911. cnop 0,4
  912. .not_dskblk btst #INTB_SOFTINT,d0
  913. beq.s .not_softint
  914. move.l irq2jmp(pc),d0
  915. beq.s .nojmp2
  916. move.l d0,a0
  917. jsr (a0) * call codehook
  918. .nojmp2
  919. move.w #INTF_SOFTINT,_custom+intreq
  920. .not_softint: movem.l (sp)+,d0-a6
  921. nop * dont smash the
  922. rte * 040/060 pipelines!
  923. ;/* Level 2: I/O Ports Interrupt (IRQ 3)
  924. * ------------------------------------
  925. */
  926. cnop 0,4
  927. Level2_IRQ: movem.l d0-a6,-(sp)
  928. move.w _custom+intreqr,d0
  929. btst #INTB_PORTS,d0
  930. beq.s .not_ports
  931. btst #3,_ciaa+ciaicr * sp_mode?
  932. beq.s .not_irc
  933. move.l irq3jmp(pc),d0
  934. beq.s .nojmp3
  935. move.l d0,a0
  936. jsr (a0) * call codehook
  937. .nojmp3
  938. .not_irc move.w #INTF_PORTS,_custom+intreq
  939. .not_ports: movem.l (sp)+,d0-a6
  940. nop * dont smash the
  941. rte * 040/060 pipelines!
  942. ;/* Level 3: Copper Interrupt (IRQ 4)
  943. * ---------------------------------
  944. */
  945. cnop 0,4
  946. Level3_IRQ: movem.l d0-a6,-(sp)
  947. move.w _custom+intreqr,d0
  948. btst #INTB_COPER,d0
  949. beq.s .notcopper
  950. move.l irq4jmp(pc),d0
  951. beq.s .nojmp4
  952. move.l d0,a0
  953. jsr (a0) * call codehook
  954. .nojmp4
  955. move.w #INTF_COPER,_custom+intreq
  956. movem.l (sp)+,d0-a6
  957. nop * dont smash the
  958. rte * 040/060 pipelines!
  959. ;/* Level 3: Vertical Blank Interrupt (IRQ 5)
  960. * -----------------------------------------
  961. */
  962. cnop 0,4
  963. .notcopper btst #INTB_VERTB,d0
  964. beq.s .notvb
  965. move.l irq5jmp(pc),d0
  966. beq.s .nojmp5
  967. move.l d0,a0
  968. jsr (a0) * call codehook
  969. .nojmp5
  970. move.w #INTF_VERTB,_custom+intreq
  971. movem.l (sp)+,d0-a6
  972. nop * dont smash the
  973. rte * 040/060 pipelines!
  974. ;/* Level 3: Blitter Finished Interrupt (IRQ 6)
  975. * -------------------------------------------
  976. */
  977. cnop 0,4
  978. .notvb btst #INTB_BLIT,d0 * next blit in queue?
  979. beq.s .notblitter
  980. move.l irq6jmp(pc),d0 * blit queue code ptr
  981. beq.s .nojmp6
  982. move.l d0,a0
  983. jsr (a0) * call codehook
  984. .nojmp6
  985. move.w #INTF_BLIT,_custom+intreq
  986. .notblitter movem.l (sp)+,d0-a6
  987. nop * dont smash the
  988. rte * 040/060 pipelines!
  989. ;/* Level 4: Audio Channel 0 Interrupt (IRQ 7)
  990. * ------------------------------------------
  991. */
  992. cnop 0,4
  993. Level4_IRQ: movem.l d0-a6,-(sp)
  994. move.w _custom+intreqr,d0
  995. btst #INTB_AUD0,d0
  996. beq.s .not_aud3
  997. move.l irq7jmp(pc),d0
  998. beq.s .nojmp7
  999. move.l d0,a0
  1000. jsr (a0) * call codehook
  1001. .nojmp7
  1002. move.w #INTF_AUD0,_custom+intreq * clear request
  1003. movem.l (sp)+,d0-a6
  1004. nop * dont smash the
  1005. rte * 040/060 pipelines!
  1006. ;/* Level 4: Audio Channel 1 Interrupt (IRQ 8)
  1007. * ------------------------------------------
  1008. */
  1009. cnop 0,4
  1010. .not_aud3: btst #INTB_AUD1,d0
  1011. beq.s .not_aud2
  1012. move.l irq8jmp(pc),d0
  1013. beq.s .nojmp8
  1014. move.l d0,a0
  1015. jsr (a0) * call codehook
  1016. .nojmp8
  1017. move.w #INTF_AUD1,_custom+intreq * clear request
  1018. movem.l (sp)+,d0-a6
  1019. nop * dont smash the
  1020. rte * 040/060 pipelines!
  1021. ;/* Level 4: Audio Channel 2 Interrupt (IRQ 9)
  1022. * ------------------------------------------
  1023. */
  1024. cnop 0,4
  1025. .not_aud2: btst #INTB_AUD2,d0
  1026. beq.s .not_aud1
  1027. move.l irq9jmp(pc),d0
  1028. beq.s .nojmp9
  1029. move.l d0,a0
  1030. jsr (a0) * call codehook
  1031. .nojmp9
  1032. move.w #INTF_AUD2,_custom+intreq * clear request
  1033. movem.l (sp)+,d0-a6
  1034. nop * dont smash the
  1035. rte * 040/060 pipelines!
  1036. ;/* Level 4: Audio Channel 3 Interrupt (IRQ 10)
  1037. * -------------------------------------------
  1038. */
  1039. cnop 0,4
  1040. .not_aud1: btst #INTB_AUD3,d0
  1041. beq.s .not_aud0
  1042. move.l irq10jmp(pc),d0
  1043. beq.s .nojmp10
  1044. move.l d0,a0
  1045. jsr (a0) * call codehook
  1046. .nojmp10
  1047. move.w #INTF_AUD3,_custom+intreq * clear request
  1048. .not_aud0: movem.l (sp)+,d0-a6
  1049. nop * dont smash the
  1050. rte * 040/060 pipelines!
  1051. ;/* Level 5: Read Buffer Full Interrupt (IRQ 11)
  1052. * --------------------------------------------
  1053. */
  1054. cnop 0,4
  1055. Level5_IRQ: movem.l d0-a6,-(sp)
  1056. move.w _custom+intreqr,d0
  1057. btst #INTB_RBF,d0
  1058. beq.s .not_rbf
  1059. move.l irq11jmp(pc),d0
  1060. beq.s .nojmp11
  1061. move.l d0,a0
  1062. jsr (a0) * call codehook
  1063. .nojmp11
  1064. move.w #INTF_RBF,_custom+intreq * clear request
  1065. movem.l (sp)+,d0-a6
  1066. nop * dont smash the
  1067. rte * 040/060 pipelines!
  1068. ;/* Level 5: Disk Sync Interrupt (IRQ 12)
  1069. * ------------------------------------
  1070. */
  1071. cnop 0,4
  1072. .not_rbf: btst #INTB_DSKSYNC,d0
  1073. beq.s .not_dsk
  1074. move.l irq12jmp(pc),d0
  1075. beq.s .nojmp12
  1076. move.l d0,a0
  1077. jsr (a0) * call codehook
  1078. .nojmp12
  1079. move.w #INTF_DSKSYNC,_custom+intreq * clear request
  1080. .not_dsk movem.l (sp)+,d0-a6
  1081. nop * dont smash the
  1082. rte * 040/060 pipelines!
  1083. ;/* Level 6: External Interrupt (IRQ 13)
  1084. * ------------------------------------
  1085. */
  1086. cnop 0,4
  1087. Level6_IRQ: tst.b _ciab+ciaicr * trigger cia..
  1088. movem.l d0-a6,-(sp)
  1089. move.w _custom+intreqr,d0
  1090. btst #INTB_EXTER,d0
  1091. beq.s .not_exter
  1092. move.l irq13jmp(pc),d0
  1093. beq.s .nojmp13
  1094. move.l d0,a0
  1095. jsr (a0) * call codehook
  1096. .nojmp13
  1097. move.w #INTF_EXTER,_custom+intreq * clear request
  1098. .not_exter: movem.l (sp)+,d0-a6
  1099. nop * dont smash the
  1100. rte * 040/060 pipelines!
  1101. ;/* Level 7: Non-Maskable Interrupt (IRQ 14)
  1102. * -----------------------------------------
  1103. */
  1104. cnop 0,4
  1105. Level7_IRQ: movem.l d0-a6,-(sp)
  1106. move.l irq14jmp(pc),d0
  1107. beq.s .nojmp14
  1108. move.l d0,a0
  1109. jsr (a0) * call codehook
  1110. .nojmp14
  1111. movem.l (sp)+,d0-a6
  1112. nop * dont smash the
  1113. rte * 040/060 pipelines!
  1114. ;/* Level 3: (Sync) from Copperlist Generated Interrupt (IRQ 5)
  1115. * -----------------------------------------------------------
  1116. */
  1117. cnop 0,4
  1118. CopperIrqSync: lea _custom,a5
  1119. move.w #INTF_COPER,intreq(a5)
  1120. wait_for_bit: btst #INTB_COPER,intreqr+1(a5)
  1121. beq.s wait_for_bit
  1122. rts
  1123. cnop 0,4
  1124. _LVOGetKeys: move.b _ciaa+ciasdr,d0 * get key
  1125. not.b d0 * normalise key..
  1126. ror.b #1,d0 * shift to correct bits
  1127. swap d0 * put in upper word
  1128. move.b #CIACRAF_TODIN+CIACRAF_SPMODE+CIACRAF_LOAD,_ciaa+ciacra
  1129. lea _custom+vhposr,a1
  1130. move.b (a1),d0
  1131. .waitvb1: cmp.b (a1),d0 * wait 1 scanline
  1132. beq.s .waitvb1
  1133. move.b (a1),d0
  1134. .waitvb2: cmp.b (a1),d0 * wait 1 scanline
  1135. beq.s .waitvb2
  1136. move.b (a1),d0
  1137. .waitvb3: cmp.b (a1),d0 * wait 1 scanline
  1138. beq.s .waitvb3
  1139. swap d0 * restore key from word
  1140. move.b #CIACRAF_START+CIACRAF_RUNMODE,_ciaa+ciacra
  1141. btst #7,d0
  1142. bne.s KeyUp * key released?
  1143. andi.w #%01111111,d0 * mask keyrelease bit 7
  1144. move.b d0,Key-KeyMatrix(a0) * store current key..
  1145. st.b (a0,d0.w) * set key in matrix..
  1146. rts
  1147. cnop 0,4
  1148. KeyUp: andi.w #%01111111,d0 * mask keyrelease bit 7
  1149. st.b Key-KeyMatrix(a0) * store keyup for key..
  1150. sf.b (a0,d0.w) * clear key
  1151. rts
  1152. *-------------- Note: This copperlist *must* be in chipram to be shown!
  1153. nullcopper: dc.w bplcon0,$0200 * no bitplanes
  1154. dc.w color,$0000 * black paper color
  1155. dc.w color,$0000 * black paper color
  1156. dc.w $ffff,$fffe * terminate copperlist
  1157. DosName dc.b 'dos.library',0
  1158. GfxName dc.b 'graphics.library',0
  1159. IntName dc.b 'intuition.library',0
  1160. wbn dc.b 'Workbench',0
  1161. audn dc.b 'audio.device',0
  1162. MiscName dc.b 'misc.resource',0
  1163. SerName dc.b 'serial.hog',0
  1164. ParName dc.b 'parallel.hog',0
  1165. * Jump Address Level No Description
  1166. * ------------ ----- -- -------------------------
  1167. cnop 0,4
  1168. irqtab: dc.w irq0jmp-irqtab 1 00: Transmit Buffer Empty IRQ
  1169. dc.w irq1jmp-irqtab 1 01: Disk Block IRQ
  1170. dc.w irq2jmp-irqtab 1 02: Software Generated IRQ
  1171. dc.w irq3jmp-irqtab 2 03: I/O Ports IRQ
  1172. dc.w irq4jmp-irqtab 3 04: Copper Triggered IRQ
  1173. dc.w irq5jmp-irqtab 3 05: Vertical Blank IRQ
  1174. dc.w irq6jmp-irqtab 3 06: Blitter Finished IRQ
  1175. dc.w irq7jmp-irqtab 4 07: Audio Channel 0 IRQ
  1176. dc.w irq8jmp-irqtab 4 08: Audio Channel 1 IRQ
  1177. dc.w irq9jmp-irqtab 4 09: Audio Channel 2 IRQ
  1178. dc.w irq10jmp-irqtab 4 10: Audio Channel 3 IRQ
  1179. dc.w irq11jmp-irqtab 5 11: Read Buffer Full IRQ
  1180. dc.w irq12jmp-irqtab 5 12: Disk Sync IRQ
  1181. dc.w irq13jmp-irqtab 6 13: External CIA-B IRQ
  1182. dc.w irq14jmp-irqtab 7 14: Non Maskable IRQ
  1183. dc.w nullcode-irqtab - 15: -- not used
  1184. irq0jmp: ds.l 1
  1185. irq1jmp: ds.l 1
  1186. irq2jmp: ds.l 1
  1187. irq3jmp: ds.l 1
  1188. irq4jmp: ds.l 1
  1189. irq5jmp: ds.l 1
  1190. irq6jmp: ds.l 1
  1191. irq7jmp: ds.l 1
  1192. irq8jmp: ds.l 1
  1193. irq9jmp: ds.l 1
  1194. irq10jmp: ds.l 1
  1195. irq11jmp: ds.l 1
  1196. irq12jmp: ds.l 1
  1197. irq13jmp: ds.l 1
  1198. irq14jmp: ds.l 1
  1199. nullcode: ds.l 1
  1200. ourint: ds.w 1
  1201. cnop 0,4
  1202. aud_ioreq: dc.l 0,0
  1203. dc.b 5,127 * type, pri
  1204. dc.l 0 * name
  1205. aud_msgport: dc.l 0 * replyport
  1206. dc.w 68 * length
  1207. dc.l 0 * io_Device
  1208. dc.l 0 * io_Unit
  1209. aud_cmd: dc.w 0 * io_Command
  1210. aud_flags: dc.b 0 * io_Flags
  1211. aud_error: dc.b 0 * io_Error
  1212. aud_allockey: dc.w 0 * ioa_AllocKey
  1213. aud_chanmap dc.l 0 * ioa_Data
  1214. dc.l 1 * ioa_Length
  1215. dc.w 0,0,0 * ioa_Period, Volume, Cycles
  1216. dc.w 0,0,0,0,0,0,0,0,0,0 * ioa_WriteMsg
  1217. aud_messageport:dc.l 0,0 * succ,pred
  1218. dc.b 4,0 * type = NT_MSGPORT, priority
  1219. dc.l 0 * name
  1220. dc.b 0 * flags
  1221. aud_signal: dc.b 0 * signal bit = PA_SIGNAL
  1222. aud_task: dc.l 0 * task
  1223. dc.l 0,0,0 * head,tail,tailpred
  1224. dc.b 5,0 * type
  1225. cnop 0,4
  1226. _VBR: ds.l 1 * cpu vectorbase address
  1227. _DOSBase: ds.l 1 * dos base
  1228. _GfxBase: ds.l 1 * graphics base
  1229. _IntuitionBase: ds.l 1 * intuition base
  1230. _MiscBase: dc.l 0 * misc resource base
  1231. oldres: ds.l 1 * Old sprite resolution
  1232. wbscreen: ds.l 1 * WB screen
  1233. taglist: ds.l 1 * VTAG cm (set resn/get resn)
  1234. res: ds.l 1 * resolution
  1235. tagdone: ds.l 2 * TAG_DONE,0
  1236. flags: ds.l 1 * Takeover input flags
  1237. zero_copy: ds.l 1 * zeropage copy address
  1238. old_VBR: ds.l 1 * old VBR
  1239. old_taskpri: ds.l 1 * old task priority
  1240. our_task: ds.l 1 * old task address
  1241. sysview: ds.l 1 * system view address
  1242. oldsysstack: ds.l 1 * old sp:superstate/userstate
  1243. old_cachebits: ds.l 1 * old cache control bits
  1244. old_WindowPtr: ds.l 1 * old window ptr address
  1245. VecStore: ds.l 64 * preserve buffer
  1246. old_dmacon: ds.w 1 * custom chip dma control bits
  1247. old_intena: ds.w 1 * custom chip interrupt bits
  1248. old_intreq: ds.w 1 * custom chip irq requests
  1249. old_adkcon: ds.w 1 * custom chip uart control bits
  1250. error: ds.b 1 * if = 0 an error occured
  1251. padding: ds.b 1 * else takeover was successful
  1252. audio_alloc: ds.b 1 * Flag: audio was allocated succesfully
  1253. ciaa_store: ds.b 16 * ciaa settings (stored)
  1254. ciab_store: ds.b 16 * ciab settings (stored)
  1255. KeyMatrix ds.b 256
  1256. Key ds.b 2
  1257. channel_map: dc.b %1111 * all 4 channels or nothing (alloc map)