hardware.pas 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2014 by Free Pascal development team
  4. hardware definitions
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {
  12. registers and bits in the Complex Interface Adapter (CIA) chip
  13. }
  14. unit hardware;
  15. interface
  16. uses
  17. Exec;
  18. {
  19. * ciaa is on an ODD Pointer (e.g. the low Byte) -- $bfe001
  20. * ciab is on an EVEN Pointer (e.g. the high Byte) -- $bfd000
  21. *
  22. * do this to get the definitions:
  23. * extern struct CIA ciaa, ciab;
  24. }
  25. Type
  26. pCIA = ^tCIA;
  27. tCIA = record
  28. ciapra : Byte;
  29. pad0 : Array [0..254] of Byte;
  30. ciaprb : Byte;
  31. pad1 : Array [0..254] of Byte;
  32. ciaddra : Byte;
  33. pad2 : Array [0..254] of Byte;
  34. ciaddrb : Byte;
  35. pad3 : Array [0..254] of Byte;
  36. ciatalo : Byte;
  37. pad4 : Array [0..254] of Byte;
  38. ciatahi : Byte;
  39. pad5 : Array [0..254] of Byte;
  40. ciatblo : Byte;
  41. pad6 : Array [0..254] of Byte;
  42. ciatbhi : Byte;
  43. pad7 : Array [0..254] of Byte;
  44. ciatodlow : Byte;
  45. pad8 : Array [0..254] of Byte;
  46. ciatodmid : Byte;
  47. pad9 : Array [0..254] of Byte;
  48. ciatodhi : Byte;
  49. pad10 : Array [0..254] of Byte;
  50. unusedreg : Byte;
  51. pad11 : Array [0..254] of Byte;
  52. ciasdr : Byte;
  53. pad12 : Array [0..254] of Byte;
  54. ciaicr : Byte;
  55. pad13 : Array [0..254] of Byte;
  56. ciacra : Byte;
  57. pad14 : Array [0..254] of Byte;
  58. ciacrb : Byte;
  59. end;
  60. Const
  61. { interrupt control register bit numbers }
  62. CIAICRB_TA = 0;
  63. CIAICRB_TB = 1;
  64. CIAICRB_ALRM = 2;
  65. CIAICRB_SP = 3;
  66. CIAICRB_FLG = 4;
  67. CIAICRB_IR = 7;
  68. CIAICRB_SETCLR = 7;
  69. { control register A bit numbers }
  70. CIACRAB_START = 0;
  71. CIACRAB_PBON = 1;
  72. CIACRAB_OUTMODE = 2;
  73. CIACRAB_RUNMODE = 3;
  74. CIACRAB_LOAD = 4;
  75. CIACRAB_INMODE = 5;
  76. CIACRAB_SPMODE = 6;
  77. CIACRAB_TODIN = 7;
  78. { control register B bit numbers }
  79. CIACRBB_START = 0;
  80. CIACRBB_PBON = 1;
  81. CIACRBB_OUTMODE = 2;
  82. CIACRBB_RUNMODE = 3;
  83. CIACRBB_LOAD = 4;
  84. CIACRBB_INMODE0 = 5;
  85. CIACRBB_INMODE1 = 6;
  86. CIACRBB_ALARM = 7;
  87. { interrupt control register masks }
  88. CIAICRF_TA = $01;
  89. CIAICRF_TB = $02;
  90. CIAICRF_ALRM = $04;
  91. CIAICRF_SP = $08;
  92. CIAICRF_FLG = $10;
  93. CIAICRF_IR = $80;
  94. CIAICRF_SETCLR = $80;
  95. { control register A register masks }
  96. CIACRAF_START = $01;
  97. CIACRAF_PBON = $02;
  98. CIACRAF_OUTMODE = $04;
  99. CIACRAF_RUNMODE = $08;
  100. CIACRAF_LOAD = $10;
  101. CIACRAF_INMODE = $20;
  102. CIACRAF_SPMODE = $40;
  103. CIACRAF_TODIN = $80;
  104. { control register B register masks }
  105. CIACRBF_START = $01;
  106. CIACRBF_PBON = $02;
  107. CIACRBF_OUTMODE = $04;
  108. CIACRBF_RUNMODE = $08;
  109. CIACRBF_LOAD = $10;
  110. CIACRBF_INMODE0 = $20;
  111. CIACRBF_INMODE1 = $40;
  112. CIACRBF_ALARM = $80;
  113. { control register B INMODE masks }
  114. CIACRBF_IN_PHI2 = 0;
  115. CIACRBF_IN_CNT = CIACRBF_INMODE0;
  116. CIACRBF_IN_TA = CIACRBF_INMODE1;
  117. CIACRBF_IN_CNT_TA = CIACRBF_INMODE0 + CIACRBF_INMODE1;
  118. {
  119. * Port definitions -- what each bit in a cia peripheral register is tied to
  120. }
  121. { ciaa port A (0xbfe001) }
  122. CIAB_GAMEPORT1 = 7; { gameport 1, pin 6 (fire button*) }
  123. CIAB_GAMEPORT0 = 6; { gameport 0, pin 6 (fire button*) }
  124. CIAB_DSKRDY = 5; { disk ready* }
  125. CIAB_DSKTRACK0 = 4; { disk on track 00* }
  126. CIAB_DSKPROT = 3; { disk write protect* }
  127. CIAB_DSKCHANGE = 2; { disk change* }
  128. CIAB_LED = 1; { led light control (0==>bright) }
  129. CIAB_OVERLAY = 0; { memory overlay bit }
  130. { ciaa port B (0xbfe101) -- parallel port }
  131. { ciab port A (0xbfd000) -- serial and printer control }
  132. CIAB_COMDTR = 7; { serial Data Terminal Ready* }
  133. CIAB_COMRTS = 6; { serial Request to Send* }
  134. CIAB_COMCD = 5; { serial Carrier Detect* }
  135. CIAB_COMCTS = 4; { serial Clear to Send* }
  136. CIAB_COMDSR = 3; { serial Data Set Ready* }
  137. CIAB_PRTRSEL = 2; { printer SELECT }
  138. CIAB_PRTRPOUT = 1; { printer paper out }
  139. CIAB_PRTRBUSY = 0; { printer busy }
  140. { ciab port B (0xbfd100) -- disk control }
  141. CIAB_DSKMOTOR = 7; { disk motorr* }
  142. CIAB_DSKSEL3 = 6; { disk select unit 3* }
  143. CIAB_DSKSEL2 = 5; { disk select unit 2* }
  144. CIAB_DSKSEL1 = 4; { disk select unit 1* }
  145. CIAB_DSKSEL0 = 3; { disk select unit 0* }
  146. CIAB_DSKSIDE = 2; { disk side select* }
  147. CIAB_DSKDIREC = 1; { disk direction of seek* }
  148. CIAB_DSKSTEP = 0; { disk step heads* }
  149. { ciaa port A (0xbfe001) }
  150. CIAF_GAMEPORT1 = 128;
  151. CIAF_GAMEPORT0 = 64;
  152. CIAF_DSKRDY = 32;
  153. CIAF_DSKTRACK0 = 16;
  154. CIAF_DSKPROT = 8;
  155. CIAF_DSKCHANGE = 4;
  156. CIAF_LED = 2;
  157. CIAF_OVERLAY = 1;
  158. { ciaa port B (0xbfe101) -- parallel port }
  159. { ciab port A (0xbfd000) -- serial and printer control }
  160. CIAF_COMDTR = 128;
  161. CIAF_COMRTS = 64;
  162. CIAF_COMCD = 32;
  163. CIAF_COMCTS = 16;
  164. CIAF_COMDSR = 8;
  165. CIAF_PRTRSEL = 4;
  166. CIAF_PRTRPOUT = 2;
  167. CIAF_PRTRBUSY = 1;
  168. { ciab port B (0xbfd100) -- disk control }
  169. CIAF_DSKMOTOR = 128;
  170. CIAF_DSKSEL3 = 64;
  171. CIAF_DSKSEL2 = 32;
  172. CIAF_DSKSEL1 = 16;
  173. CIAF_DSKSEL0 = 8;
  174. CIAF_DSKSIDE = 4;
  175. CIAF_DSKDIREC = 2;
  176. CIAF_DSKSTEP = 1;
  177. Type
  178. pAudChannel = ^tAudChannel;
  179. tAudChannel = record
  180. ac_ptr : Pointer; { ptr to start of waveform data }
  181. ac_len : Word; { length of waveform in words }
  182. ac_per : Word; { sample period }
  183. ac_vol : Word; { volume }
  184. ac_dat : Word; { sample pair }
  185. ac_pad : Array [0..1] of Word; { unused }
  186. end;
  187. pSpriteDef = ^tSpriteDef;
  188. tSpriteDef = record
  189. pos : Word;
  190. ctl : Word;
  191. dataa : Word;
  192. datab : Word;
  193. end;
  194. pCustom = ^tCustom;
  195. tCustom = record
  196. bltddat : Word;
  197. dmaconr : Word;
  198. vposr : Word;
  199. vhposr : Word;
  200. dskdatr : Word;
  201. joy0dat : Word;
  202. joy1dat : Word;
  203. clxdat : Word;
  204. adkconr : Word;
  205. pot0dat : Word;
  206. pot1dat : Word;
  207. potinp : Word;
  208. serdatr : Word;
  209. dskbytr : Word;
  210. intenar : Word;
  211. intreqr : Word;
  212. dskpt : Pointer;
  213. dsklen : Word;
  214. dskdat : Word;
  215. refptr : Word;
  216. vposw : Word;
  217. vhposw : Word;
  218. copcon : Word;
  219. serdat : Word;
  220. serper : Word;
  221. potgo : Word;
  222. joytest : Word;
  223. strequ : Word;
  224. strvbl : Word;
  225. strhor : Word;
  226. strlong : Word;
  227. bltcon0 : Word;
  228. bltcon1 : Word;
  229. bltafwm : Word;
  230. bltalwm : Word;
  231. bltcpt : Pointer;
  232. bltbpt : Pointer;
  233. bltapt : Pointer;
  234. bltdpt : Pointer;
  235. bltsize : Word;
  236. pad2d : Byte;
  237. bltcon0l : Byte;
  238. bltsizv : Word;
  239. bltsizh : Word;
  240. bltcmod : Word;
  241. bltbmod : Word;
  242. bltamod : Word;
  243. bltdmod : Word;
  244. pad34 : Array [0..3] of Word;
  245. bltcdat : Word;
  246. bltbdat : Word;
  247. bltadat : Word;
  248. pad3b : Array [0..2] of Word;
  249. deniseid : Word;
  250. dsksync : Word;
  251. cop1lc : Longint;
  252. cop2lc : Longint;
  253. copjmp1 : Word;
  254. copjmp2 : Word;
  255. copins : Word;
  256. diwstrt : Word;
  257. diwstop : Word;
  258. ddfstrt : Word;
  259. ddfstop : Word;
  260. dmacon : Word;
  261. clxcon : Word;
  262. intena : Word;
  263. intreq : Word;
  264. adkcon : Word;
  265. aud : Array [0..3] of tAudChannel;
  266. bplpt : Array [0..7] of Pointer;
  267. bplcon0 : Word;
  268. bplcon1 : Word;
  269. bplcon2 : Word;
  270. bplcon3 : Word;
  271. bpl1mod : Word;
  272. bpl2mod : Word;
  273. bplcon4 : Word;
  274. clxcon2 : Word;
  275. bpldat : Array [0..7] of Word;
  276. sprpt : Array [0..7] of Pointer;
  277. spr : Array [0..7] of tSpriteDef;
  278. color : Array [0..31] of Word;
  279. htotal : Word;
  280. hsstop : Word;
  281. hbstrt : Word;
  282. hbstop : Word;
  283. vtotal : Word;
  284. vsstop : Word;
  285. vbstrt : Word;
  286. vbstop : Word;
  287. sprhstrt : Word;
  288. sprhstop : Word;
  289. bplhstrt : Word;
  290. bplhstop : Word;
  291. hhposw : Word;
  292. hhposr : Word;
  293. beamcon0 : Word;
  294. hsstrt : Word;
  295. vsstrt : Word;
  296. hcenter : Word;
  297. diwhigh : Word;
  298. padf3 : Array [0..10] of Word;
  299. fmode : Word;
  300. end;
  301. CONST
  302. { defines for beamcon register }
  303. VARVBLANK = $1000; { Variable vertical blank enable }
  304. LOLDIS = $0800; { long line disable }
  305. CSCBLANKEN = $0400; { redirect composite sync }
  306. VARVSYNC = $0200; { Variable vertical sync enable }
  307. VARHSYNC = $0100; { Variable horizontal sync enable }
  308. VARBEAM = $0080; { variable beam counter enable }
  309. DISPLAYDUAL = $0040; { use UHRES pointer AND standard pointers }
  310. DISPLAYPAL = $0020; { set decodes to generate PAL display }
  311. VARCSYNC = $0010; { Variable composite sync enable }
  312. CSBLANK = $0008; { Composite blank out to CSY* pin }
  313. CSYNCTRUE = $0004; { composite sync TRUE signal }
  314. VSYNCTRUE = $0002; { vertical sync TRUE }
  315. HSYNCTRUE = $0001; { horizontal sync TRUE }
  316. { new defines for bplcon0 }
  317. USE_BPLCON3 = 1;
  318. { new defines for bplcon2 }
  319. BPLCON2_ZDCTEN = 1024; { colormapped genlock bit }
  320. BPLCON2_ZDBPEN = 2048; { use bitplane as genlock bits }
  321. BPLCON2_ZDBPSEL0 = 4096; { three bits to select one }
  322. BPLCON2_ZDBPSEL1 = 8192; { of 8 bitplanes in }
  323. BPLCON2_ZDBPSEL2 = 16384; { ZDBPEN genlock mode }
  324. { defines for bplcon3 register }
  325. BPLCON3_EXTBLNKEN = 1; { external blank enable }
  326. BPLCON3_EXTBLKZD = 2; { external blank ored into trnsprncy }
  327. BPLCON3_ZDCLKEN = 4; { zd pin outputs a 14mhz clock}
  328. BPLCON3_BRDNTRAN = 16; { border is opaque }
  329. BPLCON3_BRDNBLNK = 32; { border is opaque }
  330. Const
  331. ADKB_SETCLR = 15; { standard set/clear bit }
  332. ADKB_PRECOMP1 = 14; { two bits of precompensation }
  333. ADKB_PRECOMP0 = 13;
  334. ADKB_MFMPREC = 12; { use mfm style precompensation }
  335. ADKB_UARTBRK = 11; { force uart output to zero }
  336. ADKB_WORDSYNC = 10; { enable DSKSYNC register matching }
  337. ADKB_MSBSYNC = 9; { (Apple GCR Only) sync on MSB for reading }
  338. ADKB_FAST = 8; { 1 -> 2 us/bit (mfm), 2 -> 4 us/bit (gcr) }
  339. ADKB_USE3PN = 7; { use aud chan 3 to modulate period of ?? }
  340. ADKB_USE2P3 = 6; { use aud chan 2 to modulate period of 3 }
  341. ADKB_USE1P2 = 5; { use aud chan 1 to modulate period of 2 }
  342. ADKB_USE0P1 = 4; { use aud chan 0 to modulate period of 1 }
  343. ADKB_USE3VN = 3; { use aud chan 3 to modulate volume of ?? }
  344. ADKB_USE2V3 = 2; { use aud chan 2 to modulate volume of 3 }
  345. ADKB_USE1V2 = 1; { use aud chan 1 to modulate volume of 2 }
  346. ADKB_USE0V1 = 0; { use aud chan 0 to modulate volume of 1 }
  347. ADKF_SETCLR = $8000;
  348. ADKF_PRECOMP1 = $4000;
  349. ADKF_PRECOMP0 = $2000;
  350. ADKF_MFMPREC = $1000;
  351. ADKF_UARTBRK = $0800;
  352. ADKF_WORDSYNC = $0400;
  353. ADKF_MSBSYNC = $0200;
  354. ADKF_FAST = $0100;
  355. ADKF_USE3PN = $0080;
  356. ADKF_USE2P3 = $0040;
  357. ADKF_USE1P2 = $0020;
  358. ADKF_USE0P1 = $0010;
  359. ADKF_USE3VN = $0008;
  360. ADKF_USE2V3 = $0004;
  361. ADKF_USE1V2 = $0002;
  362. ADKF_USE0V1 = $0001;
  363. ADKF_PRE000NS = 0; { 000 ns of precomp }
  364. ADKF_PRE140NS = ADKF_PRECOMP0; { 140 ns of precomp }
  365. ADKF_PRE280NS = ADKF_PRECOMP1; { 280 ns of precomp }
  366. ADKF_PRE560NS = ADKF_PRECOMP0 + ADKF_PRECOMP1; { 560 ns of precomp }
  367. Const
  368. HSIZEBITS = 6;
  369. VSIZEBITS = 16 - HSIZEBITS;
  370. HSIZEMASK = $3F; { 2^6 - 1 }
  371. VSIZEMASK = $3FF; { 2^10 - 1 }
  372. MAXBYTESPERROW = 128;
  373. { definitions for blitter control register 0 }
  374. ABC = $80;
  375. ABNC = $40;
  376. ANBC = $20;
  377. ANBNC = $10;
  378. NABC = $08;
  379. NABNC = $04;
  380. NANBC = $02;
  381. NANBNC = $01;
  382. { some commonly used operations }
  383. A_OR_B = ABC + ANBC + NABC + ABNC + ANBNC + NABNC;
  384. A_OR_C = ABC + NABC + ABNC + ANBC + NANBC + ANBNC;
  385. A_XOR_C = NABC + ABNC + NANBC + ANBNC;
  386. A_TO_D = ABC + ANBC + ABNC + ANBNC;
  387. BC0B_DEST = 8;
  388. BC0B_SRCC = 9;
  389. BC0B_SRCB = 10;
  390. BC0B_SRCA = 11;
  391. BC0F_DEST = $100;
  392. BC0F_SRCC = $200;
  393. BC0F_SRCB = $400;
  394. BC0F_SRCA = $800;
  395. BC1F_DESC = 2; { blitter descend direction }
  396. DEST = $100;
  397. SRCC = $200;
  398. SRCB = $400;
  399. SRCA = $800;
  400. ASHIFTSHIFT = 12; { bits to right align ashift value }
  401. BSHIFTSHIFT = 12; { bits to right align bshift value }
  402. { definations for blitter control register 1 }
  403. LINEMODE = $01;
  404. FILL_OR = $08;
  405. FILL_XOR = $10;
  406. FILL_CARRYIN = $04;
  407. ONEDOT = $02; { one dot per horizontal line }
  408. OVFLAG = $20;
  409. SIGNFLAG = $40;
  410. BLITREVERSE = $02;
  411. SUD = $10;
  412. SUL = $08;
  413. AUL = $04;
  414. OCTANT8 = 24;
  415. OCTANT7 = 4;
  416. OCTANT6 = 12;
  417. OCTANT5 = 28;
  418. OCTANT4 = 20;
  419. OCTANT3 = 8;
  420. OCTANT2 = 0;
  421. OCTANT1 = 16;
  422. type
  423. PBltNode = ^TBltNode;
  424. TBltNode = record
  425. n: Pbltnode;
  426. function_: Pointer;
  427. Stat: Byte;
  428. BltSize: SmallInt;
  429. BeamSync: smallint;
  430. CleanUp: Pointer;
  431. end;
  432. Const
  433. { write definitions for dmaconw }
  434. DMAF_SETCLR = $8000;
  435. DMAF_AUDIO = $000F; { 4 bit mask }
  436. DMAF_AUD0 = $0001;
  437. DMAF_AUD1 = $0002;
  438. DMAF_AUD2 = $0004;
  439. DMAF_AUD3 = $0008;
  440. DMAF_DISK = $0010;
  441. DMAF_SPRITE = $0020;
  442. DMAF_BLITTER = $0040;
  443. DMAF_COPPER = $0080;
  444. DMAF_RASTER = $0100;
  445. DMAF_MASTER = $0200;
  446. DMAF_BLITHOG = $0400;
  447. DMAF_ALL = $01FF; { all dma channels }
  448. { read definitions for dmaconr }
  449. { bits 0-8 correspnd to dmaconw definitions }
  450. DMAF_BLTDONE = $4000;
  451. DMAF_BLTNZERO = $2000;
  452. DMAB_SETCLR = 15;
  453. DMAB_AUD0 = 0;
  454. DMAB_AUD1 = 1;
  455. DMAB_AUD2 = 2;
  456. DMAB_AUD3 = 3;
  457. DMAB_DISK = 4;
  458. DMAB_SPRITE = 5;
  459. DMAB_BLITTER = 6;
  460. DMAB_COPPER = 7;
  461. DMAB_RASTER = 8;
  462. DMAB_MASTER = 9;
  463. DMAB_BLITHOG = 10;
  464. DMAB_BLTDONE = 14;
  465. DMAB_BLTNZERO = 13;
  466. Const
  467. INTB_SETCLR = 15; { Set/Clear control bit. Determines if bits }
  468. { written with a 1 get set or cleared. Bits }
  469. { written with a zero are allways unchanged }
  470. INTB_INTEN = 14; { Master interrupt (enable only ) }
  471. INTB_EXTER = 13; { External interrupt }
  472. INTB_DSKSYNC = 12; { Disk re-SYNChronized }
  473. INTB_RBF = 11; { serial port Receive Buffer Full }
  474. INTB_AUD3 = 10; { Audio channel 3 block finished }
  475. INTB_AUD2 = 9; { Audio channel 2 block finished }
  476. INTB_AUD1 = 8; { Audio channel 1 block finished }
  477. INTB_AUD0 = 7; { Audio channel 0 block finished }
  478. INTB_BLIT = 6; { Blitter finished }
  479. INTB_VERTB = 5; { start of Vertical Blank }
  480. INTB_COPER = 4; { Coprocessor }
  481. INTB_PORTS = 3; { I/O Ports and timers }
  482. INTB_SOFTINT = 2; { software interrupt request }
  483. INTB_DSKBLK = 1; { Disk Block done }
  484. INTB_TBE = 0; { serial port Transmit Buffer Empty }
  485. INTF_SETCLR = $8000;
  486. INTF_INTEN = $4000;
  487. INTF_EXTER = $2000;
  488. INTF_DSKSYNC = $1000;
  489. INTF_RBF = $0800;
  490. INTF_AUD3 = $0400;
  491. INTF_AUD2 = $0200;
  492. INTF_AUD1 = $0100;
  493. INTF_AUD0 = $0080;
  494. INTF_BLIT = $0040;
  495. INTF_VERTB = $0020;
  496. INTF_COPER = $0010;
  497. INTF_PORTS = $0008;
  498. INTF_SOFTINT = $0004;
  499. INTF_DSKBLK = $0002;
  500. INTF_TBE = $0001;
  501. IMPLEMENTATION
  502. end.