home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / c128 / text / hacking3.arc / HACKING3.TXT next >
Text File  |  1992-07-19  |  127KB  |  3,151 lines

  1.        ########
  2.    ##################
  3.  ######            ######
  4. #####
  5. #####  ####  ####      ##       #####   ####  ####  ####  ####  ####   #####
  6. #####   ##    ##      ####     ##   ##   ##  ###     ##    ####  ##   ##   ##
  7. #####   ########     ##  ##    ##        #####       ##    ## ## ##   ##
  8. #####   ##    ##    ########   ##   ##   ##  ###     ##    ##  ####   ##   ##
  9. #####  ####  ####  ####  ####   #####   ####  ####  ####  ####  ####   ######
  10. #####                                                                     ##
  11.  ######            ######        Volume 1 - Issue 3
  12.    ##################              July 15, 1992
  13.        ########
  14.  
  15. =============================================================================
  16. Editor's Notes:
  17. by Craig Taylor (duck@pembvax1.pembroke.edu)
  18.  
  19.   Here's over 3000 lines of hacking articles & such... Sorry about the length
  20. as some of the articles ran a bit overboard.  Included within is a discussion of
  21. the KERNAL routines, an examination of Rasters, and a package of burst routines
  22. for use in your own programs. If you've got any ideas for articles etc that  
  23. you'd like to see or want to hear more on a certain topic feel free to email 
  24. me. 
  25.  
  26.   I'm pleased to introduce the Demo Corner where each month we'll report 
  27. how to achieve some of the graphic and sound effects that are present in 
  28. many demos that are wondered about.
  29.  
  30.   Note: The article concerning programming and usage of the 1351 mouse has
  31. been delayed until the next issue due to time and length constraints.
  32.  
  33.   This file is available via anonymous ftp at tybalt.caltech.edu under 
  34. pub/rknop/hacking.mag.  Back issues of C= Hacking are also located there.
  35.  
  36. **************** WARNINGS, UPDATES, BUG REPORTS, ETC... **********************
  37.  
  38.   OOPS - In the last issue of C= Hacking in Mark Lawrence's File Splitter a line
  39. inadvertantly got chopped off.  The following code should be fixed between the 
  40. comments that are listed:
  41.  
  42. [.
  43.   .
  44.    .] 
  45.    { Make EXTENSION a string representation of COUNT, to be added to the
  46.       OutFileName to make things a tad easier}
  47.  
  48.     OutFileName := Concat(NewFile,'.',Copy('00',1,3-Length(Extension)),
  49.                    Extension);   {**THIS IS THE STATEMENT...**}
  50.  
  51.     { Create filename based on which part we're up to }
  52. [.
  53.   .
  54.    .]
  55.  
  56. =============================================================================
  57. Note: Permission is granted to re-distribute this "net-magazine", in whole,
  58.   freely for non-profit use. However, please contact individual authors for
  59.   permission to publish or re-distribute articles seperately.
  60.  
  61.       *** AUTHORS LISTED BELOW RETAIN ALL RIGHTS TO THEIR ARTICLES ***
  62. =============================================================================
  63. In This Issue:
  64.  
  65. Learning ML - Part 3
  66.  
  67.   In this edition we take a look at reading and writing commands to the disk
  68. drive, including reading the disk directory and error channel. This article
  69. parallels the discussion of the C=128 and C=64 KERNAL jump tables of available
  70. routines. Written by Craig Taylor.
  71.  
  72. The Demo Corner: Missing Cycles
  73.  
  74.   Everybody knows that there are 63 cycles available to the C64 processor
  75. on each scan line, except for one which only provides 23 cycles. But what
  76. happens when we add sprites and why ? Written by Pasi 'Albert' Ojala.
  77.  
  78. KERNAL 64/128
  79.  
  80.   The C=128 and C=64 jump table points to many valuable system routines is
  81. discussed and examined in detail. Written by Craig Taylor.
  82.  
  83. 64K VDC RAM and an alternate GEOS128 Background Screen
  84.  
  85.   Standard GEOS only uses the first 16K of your VDC screen.  If you have 64K
  86. of VDC RAM, and want to write an 80-column only application, you can put some
  87. of the additional VDC RAM to use as a replacement for the standard GEOS
  88. background screen.  And, in the bargain, you get an additional 16K of
  89. application FrontRAM to use! Written by Robert Knop.
  90.  
  91. GeoPaint File Format
  92.  
  93.   Written by Bruce Vrieling, this article provides an in depth description of
  94. exactly how geoPaint stores its graphic images on disk. It examines the
  95. concept of VLIR files, how graphics data is laid out on screen (from both
  96. geoPaint and the VIC's perspective), and geoPaint's graphics compression
  97. techniques.
  98.  
  99. Rasters - What They Are and How to Use Them
  100.   
  101.   Written by Bruce Vrieling, this article provides an introduction to creating
  102. special on-screen effects using the technique of raster interrupts. The
  103. basics are examined, including what they are, and how to program them. This
  104. article should provide a good starting point for someone wanting to get
  105. their feet wet in raster programming.
  106.  
  107. Bursting Your 128: The Fastload Burst Command
  108.  
  109.   Written by Craig Bruce this article covers the Fastload burst command of the
  110. 1571 and 1581 disk drives.  The Fastload command operation and protocol are
  111. discussed and a package for using the Fastload command to read regular
  112. sequential files at binary program loading speeds is presented.  To demonstrate
  113. the package, a file word counting utility is implemented and the "commented"
  114. code is included.
  115.  
  116. ============================================================================
  117. Learning ML - Part 3
  118. by Craig Taylor (duck@pembvax1.pembroke.edu)
  119.  
  120.   Last time we used a routine at $FFD2 which would print out the character code
  121. contained within the accumalator.  That location will always print the character
  122. out regardless of VIC-20, C=64, C=128 and even PET because Commodore decided 
  123. to set up some locations in high memory that would perform routines that are
  124. commonly needed.  
  125.  
  126.   Take a look now at the KERNAL 64/128 article and glance over some of the 
  127. routines and their function / purpose. This article is meant to be a companion
  128. to that article so you may want to flip back and forth as the discussion 
  129. of the program listed below is discussed.
  130.  
  131.   Note that I've borrowed Craig Bruce's notation of having listings inside. To
  132. extract the source that follows enter the following command on a Unix system:
  133.  
  134. grep '^\.@...\!' Hack3 | sed 's/^.@...\!.//' | sed 's/.@...\!//' >dir.asm
  135.  
  136. .@001! ;
  137. .@002! ; Set up computer type for computer-dependant code / 
  138. .@003! ;    Only used in displaying # routine / start of assembly setting.
  139. .@004! ; BUDDY format.
  140. .@005! ;
  141. .@006! computer = 128             ; Define as either 64 or 128.
  142.  
  143.   For both c64 and c128 users the following code works.  Within the code is 
  144. conditional assembly which means it will work on either computer assuming that
  145. the computer is equal to either 128 or 64.
  146.  
  147. .@007! 
  148. .@008! .if computer-64            ;** if computer not c64 then
  149. .@009!       .org $1300          ;   and also make sure in BANK 15 when calling
  150. .@010!                           ;   these routines.
  151. .@011! .else                      ;** else if _is_ c64, then
  152. .@012!       .org $c000
  153. .@013! .ife                       ;** end of computer-dependant code.
  154.  
  155.   Because of this (the source is in BUDDY format) the C64 and C128 are set to 
  156. assemble at different memory locations. On the C64, $c000 is 49152. On the
  157. C128 it is at 4864. Note for the C128 it is necessary to do a BANK15 before
  158. executing the code.
  159.           
  160. .@014!       .mem                ; - assemble to memory.
  161.  
  162.   This tells the assembler to actually put the code into memory.
  163.  
  164. .@015!
  165. .@016! ;;-----------------------------------------------------------------------
  166. .@017! ;; KERNAL EQUATES
  167. .@018! ;;-----------------------------------------------------------------------
  168. .@019! 
  169. .@020! setnam = $ffbd
  170. .@021! setlfs = $ffba
  171. .@022! open   = $ffc0
  172. .@023! close  = $ffc3
  173. .@024! chkin  = $ffc6
  174. .@025! chrin  = $ffcf
  175. .@026! bsout  = $ffd2
  176. .@027! clrch  = $ffcc
  177. .@028!
  178.  
  179.   These are the KERNAL routines we will actually be using. Their actual 
  180. use will be documented when we come across them within the code.  
  181.  
  182. .@029! ;;-----------------------------------------------------------------------
  183. .@030!
  184. .@031! temp   = 253
  185. .@032! charret = $0d
  186. .@033! space = $20
  187. .@034!
  188.  
  189.   Temp is set up to just be a temporary location in zero-page. Location 253 on
  190. both the C64 and C128 is unused.  Charret stands for the carriage return
  191. character and is the equivlent of a chr$(13). Space stands for the code for a 
  192. space (a chr$(32))
  193.  
  194. .@035! ;;---------------------------------------------------------------------
  195. .@036!
  196. .@037! start = *
  197. .@038!
  198. .@039!    jsr read'dir       ; Initial jump table -- Note: Will read error after
  199. .@040!    jmp read'err       ;     showing directory.
  200. .@041!
  201.  
  202.   You'll see code like this a lot -- Basically we're building what is known as
  203. a jump table. That way if we add more code to the directory or error routine we
  204. don't have to worry about our SYS call's changing. To read the directory just
  205. SYS base, to read the error channel just SYS base+3 (where BASE is 49152 on the
  206. C64, 4864 on the 128)... 
  207.  
  208.   Also the JSR JMP combination may seem a little strange but what we are doing
  209. is treating the directory routine as a subroutine and then JUMPING to the 
  210. error routine. Once we do that the RTS in read'err will return us back to basic.
  211. .@042! ;;----------------------------------------------------------------------
  212. .@043!
  213. .@044! read'dir = *
  214. .@045! 
  215. .@046! ; Opens and reads directory as a basic program.
  216. .@047! ;==
  217. .@048! ; Basic programs are read in as follows:
  218. .@049! ;                  [Ptr to Next Line]:2 [Line #]:2 [Text]:.... [$00 byte]
  219. .@050! ;                  ^^^^^^^^^^^REPEATS^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  220. .@051! ; The end of a program is signifed by the $00 byte signifying end of text
  221. .@052! ;    and the ptr's also being = $00.
  222. .@053! ;==
  223.  
  224.   There are several ways to read the directory in machine language.  What we are
  225. doing here is taking advantage of the drive's ability to allow us to load the
  226. directory as a basic program -*except*- we aren't loading it per se. We're 
  227. gonna grab each byte as it comes from the drive and interpret it ourselves
  228. instead of putting it in memory as would normally be done.
  229.  
  230.   Basic programs are stored as the following: A 2 byte pointer, a 2 byte
  231. line #, the basic text, and a null terminator and then starting over
  232. from the 2 byte pointer.  The pointer we do not need, the line # is the number
  233. of blocks the file takes up and the TEXT is the program name and file type. We
  234. know when we're finished on the line by checking for a $00 byte.
  235.  
  236. .@054!                                ; Begin by opening up the 
  237. .@055!                                ; directory file ("$").
  238. .@056!        lda #$01                ;   length is 1        
  239. .@057!        ldx #<dir               ;   lo byte pointer to file name.
  240. .@058!        ldy #>dir               ;   hi byte pointer to file name.
  241. .@059!        jsr setnam              ; - call setnam
  242.  
  243.   Okay, first we need to simulate opening the directory as a program file.
  244. SETNAM sets up the filename for the open command.  In effect we are giving the 
  245. basic syntax of open file#,device#,channel#,"filename" in reverse.
  246.  
  247. .@060!        lda #$01                ;   file # 1
  248. .@061!        ldx #$08                ;   device # 8
  249. .@062!        ldy #$00                ;   channel # 0
  250. .@063!        jsr setlfs              ; - call setlfs
  251.  
  252.   Here we specify the device #, file #, channel # in preperation for the open.
  253.  
  254. .@064!        jsr open                ; - call open
  255.  
  256.   Open up the file. This is the routine that does the real work. SETNAM and
  257. SETLFS were preparatory routines for this.
  258.  
  259. .@065!  ;
  260. .@066!  ; read in the bytes and display (skipping line links etc)
  261. .@067!  ;
  262. .@068!        ldx #$01               ;   file #1
  263. .@069!        jsr chkin              ; - call chkin to set input file #.
  264.  
  265.   Now we need to specify the input file # and tell the computer that all further
  266. chrin's are to be from file #1. (By default, it would have read from the 
  267. keyboard unless we had this here).
  268.  
  269. .@070!        jsr chrin              ; - ignore starting address (2 bytes)
  270. .@071!        jsr chrin 
  271.  
  272.   Skip the starting address -- When reading the directory it is not relevant
  273. so read the bytes and discard them.
  274.  
  275. .@072!  skip  jsr chrin              ; - ignore pointer to next line (2 bytes)
  276.  
  277.   Now we skip the pointer for the next line. This is only used when loading
  278. basic programs to re-link the lines. When listing the directory they are not
  279. needed.
  280.  
  281. .@073!  bck1  jsr chrin
  282.  
  283.   This is still part of the routine that skips the pointer to the next line, yet
  284. it has a label used below that allows us to check for end of file more easily.
  285.  
  286. .@074!  line  jsr chrin              ; - get line # lo.
  287. .@075!        sta temp               ; - store lo of line # @ temp
  288. .@076!        jsr chrin              ; - get hi of line #
  289.  
  290.   Here we get the line # as the next 2 bytes in the file.
  291.  
  292. .@077! 
  293. .@078! .if computer-64               ; * if C128 then
  294.  
  295.   Unfortunately C= did not provide a nice routine in the KERNAL to display 
  296. numeric values - however - by exploring inside the operating system a way to 
  297. display numbers is there.  Note that the following may look confusing -- if it
  298. does just rest assured it will print out the line # correctly.
  299.   
  300. .@079!        sta $61
  301. .@080!        ldy temp
  302. .@081!        sty $60
  303. .@082!        lda #$00
  304. .@083!        sta $63
  305. .@084!        ldy temp                ;   store values for conversion.
  306. .@085!        jsr $ba07               ; - MONITOR routine: convert to BCD values
  307. .@086!        lda #$00
  308. .@087!        ldx #$08
  309. .@088!        ldy #$03
  310. .@089!        jsr $ba5d               ; - MONITOR routine: print BCD 
  311. .@090!                                ;values in decimal
  312.  
  313.   This is the C128 version which uses some of the MONITOR routines to display
  314. the numeric block size.
  315.  
  316. .@091! .else                          ; * else if c64
  317. .@092!        ldx temp 
  318. .@093!        jsr $bdcd               ; - print line # (w/in ROM routine).
  319. .@094! .ife                           ; * end of computer dependant code.
  320.  
  321.   This is the C64 code to display a numeric value
  322.   (notice how much simplified it is over the C128)...
  323.  
  324. .@095!
  325. .@096!        lda #space
  326. .@097!        jsr bsout               ; - print space
  327.  
  328.   Let's print a space between the filename and the block size.
  329.  
  330. .@098!  gtasc jsr chrin               ; - start printing filename until 
  331. .@099!                                ;end of line.
  332. .@100!        beq chck                ;   (Zero signifies eol).
  333. .@101!        jsr bsout               ; - Print character
  334. .@102!        sec
  335. .@103!        bcs gtasc               ;   and jump back.
  336.  
  337.   Now we start getting a character (line #98), if zero we branch out of the loop
  338.  (line #100), else we display the character (#101), and jump back (#102-03).
  339.  
  340. .@104!  chck  lda #charret            ; - Else we need to start the next line
  341. .@105!        jsr bsout               ;   Print a carriage return.
  342.  
  343.   Ah, we got to a null byte so that's the end of this line - display a car/ret.
  344.  
  345. .@106!        jsr chrin               ; - And get the next pointer
  346. .@107!        bne bck1                ;   If non-zero go, strip other ptr,
  347. .@108!                                ; and continue.
  348.  
  349.   This is where we branch back -- we are checking here for 2 null bytes on 
  350. input.  We get the first byte of the pointer and if it's non-zero then we know
  351. it's not the end of the directory so we jump back to discard the second byte at
  352. line #73.
  353.  
  354. .@109!        jsr chrin               ; - Else check 2nd byte of pointer
  355. .@110!        bne line                ;   as if both 0 then = end of directory.
  356.  
  357.   This is a continuation of the checking above. This time we're getting the 
  358. 2nd byte and checking for 0.  If it's not we jump back to get and display the
  359. line # etc. If it is 0 then that means we had $0000 for the next pointer which
  360. means that it's the end of the directory.
  361.  
  362. .@111!  ;
  363. .@112!  ;had 3 0's in a row so end of prog
  364. .@113!  ;now close the file.
  365. .@114!  ;
  366. .@115!        lda #$01                ;   file # to close
  367. .@116!        jsr close               ; - so close it
  368. .@117!        jsr clrch               ; - clear all channels
  369. .@118!        rts                     ; - and return to basic
  370. .@119!
  371.  
  372.   We then close the file by specifying the file # and calling close. We then 
  373. tell the computer to reset all the default input / output devices by calling
  374. clrch (remember we changed the default input channel??). And then we can return
  375. to where this routine was called from.
  376.  
  377. .@120! ; FILENAME string
  378. .@121! dir    .asc "$"
  379.  
  380.   This is the string that is pointed to by the SETNAM call. Note that a search
  381. pattern could be set by
  382.       line#121:       .asc "$hack*" 
  383. and by changing the length set in .A in the call in line #56.
  384.  
  385. .@122!
  386. .@123! ;;-----------------------------------------------------------------------
  387. .@124!
  388. .@125! read'err = *
  389. .@126! 
  390. .@127! ; This routine simply grabs bytes from a channel 15 it opens up until
  391. .@128! ;   a car/ret byte is found. Then it closes and returns.
  392. .@129! 
  393.  
  394.   Reading the error channel is much much more simpler than reading the 
  395. directory.  Basically we just open up the channel (specifying a null name) and
  396. repeatadly get bytes until a car/ret is found.
  397.  
  398. .@130! rderr  lda #$00                ;   length is 0
  399. .@131!        jsr setnam              ; - call setname
  400.  
  401.   Setup so we don't specify a name (length = 0).
  402.  
  403. .@132!        lda #$0f                ;   file # (15)
  404. .@133!        ldx #$08                ;   device # (08)
  405. .@134!        ldy #$0f                ;   channel # (15)
  406. .@135!        jsr setlfs              ; - set logical file #
  407.  
  408.   Do the equivlent of open 15,8,15.
  409.  
  410. .@136!        jsr open                ; - and open it.
  411.  
  412.   Open it.
  413.  
  414. .@137!  ;specify file as input
  415. .@138!        ldx #$0f                ;   file 15 is input
  416. .@139!        jsr chkin               ; - so specify it.
  417.  
  418.   Now set up file # 15 as input so we can start getting, displaying etc until
  419. a car/ret is found.
  420.  
  421. .@140!  ;now read in file
  422. .@141!  loop  jsr chrin               ; - read char
  423. .@142!        jsr bsout               ; - print char
  424. .@143!        cmp #charret            ;   is it return?
  425. .@144!        bne loop                ; - if not jmp back
  426.  
  427.   Read in and display the characters from the error channel until a char/ret is
  428. found.
  429.  
  430. .@145!  ;now close the file
  431. .@146!        lda #$0f                ;   file #
  432. .@147!        jsr close               ; - close the file
  433. .@148!        jsr clrch               ;   restore i/o
  434.  
  435.   And once it is, we close the file and restore the default i/o settings.
  436.  
  437. .@149!  ;now return to basic
  438. .@150!        rts
  439.  
  440.   And return to our caller, in this case - basic.
  441.  
  442. ============================================================================
  443. [ The Demo Corner is going to be a column where each month we'll be 
  444.   introduced to a new feature (some people call them bugs, we'll call them
  445.   features) of the Commodore 64 or 128 in the Video and Sound areas that 
  446.   have commonly been shown on demos but with no mention of how to accomplish
  447.   them. Note that readers may also want to take a look at the introduction
  448.   to Rasters elsewhere in this magazine.]
  449.  
  450. The Demo Corner: Missing Cycles
  451. by Pasi 'Albert' Ojala   (po87553@cs.tut.fi albert@cc.tut.fi)
  452.                           Written on  15-May-91  Translation 30-May-92
  453.  
  454.  
  455.                           Missing Cycles
  456.                           --------------
  457.        [all timings are in PAL, the principle applies to NTSC too]
  458.  
  459. Everybody knows that there are 63 cycles available to the C64 processor on
  460. each scan line, except for one which only provides 23 cycles (later referred
  461. to as a "bad" scan line). But what happens when we add sprites and why ?
  462.  
  463. In the C64, the VIC (video interface controller) has much more to do than
  464. just showing graphics on the screen. It also handles the memory refresh.
  465. On each scanline, it has to refresh five rows in the memory matrix and
  466. fetch fourty bytes of graphics data.
  467.  
  468. The VIC does all of this during the cycles (phase 1) that the processor is
  469. not using the memory.  These cycles, however, are not sufficient when the
  470. VIC also needs to access the character and color codes for the next row.
  471. The memory bus can't be used by the CPU and the VIC at the same time, so CPU
  472. access to the bus must be denied to allow the VIC to fetch its data.
  473. Fortunately, the VIC bus (12-bit wide) allows the character (8 bits) and
  474. color (4 bits) codes to be fetched at the same time.
  475.  
  476.  
  477. _Understanding how sprites work_
  478.  
  479. If there are sprites on the screen, the VIC needs even more cycles to fetch
  480. all of the graphics data. Scan lines are time divided so that there is
  481. enough time for all action during one line. On each line, the sprite
  482. image pointers are fetched during phase 1. If the sprite is to be displayed
  483. on that line, the three bytes of image data are fetched right after that.
  484. Out of these three fetches, two take place during phase 2 of the clock,
  485. so the processor will lose these. On average, two clock cycles are lost
  486. for each sprite that is displayed on that line.
  487.  
  488. But how is it possible for all eight sprites to only take 16-19 cycles
  489. (depending on the timing) when we have observed that one sprite requires
  490. three cycles? And why do sprites 0, 2, 4, 6 and 7 together take up as many
  491. cycles as all eight sprites ? The answer may be found in the way the VIC
  492. tells the CPU that it needs additional cycles.
  493.  
  494.  
  495. _The BA signal_
  496.  
  497. When the VIC wants to use the bus, the BA (Bus Available) signal goes
  498. inactive. This will happen three cycles before the bus must be released !
  499. During these three cycles, the CPU must complete all memory accesses or
  500. delay them until it has the bus again.
  501.  
  502. The CPU either completes the current instruction in the remaining cycles
  503. or sits and waits for the bus to become available again. It can't execute
  504. a new instruction as long as it doesn't have the bus. This is why cycles
  505. seem to be lost (besides those stolen directly for the sprites). Usually,
  506. all 8 sprites take 17 cycles while one sprite takes three cycles. However,
  507. the CPU may continue to execute an instruction if it does not use the bus.
  508.  
  509.  
  510. _Theory and speculation_
  511.  
  512. Let's suppose that all the sprites are enabled and on the same scan line.
  513. Then, the VIC steals 16 cycles (2 cycles for each sprite) for the memory
  514. fetches and 3 cycles as overhead for the BA signal, for a total of 19 cycles.
  515. However, it will be usually less because the CPU will use some of the cycles
  516. when the bus request is pending.
  517.  
  518. If we now disable sprite 4, no cycles are released for the CPU's use. This
  519. is because during the previous sprite 4 data fetch, the VIC already signals
  520. that it needs the bus for the sprite 5 data fetch and BA stays low (Refer
  521. to the timing chart). Thus, the CPU never sees BA go high during sprite 4
  522. and 2 cycles are still lost.
  523.  
  524. Accordingly, if we only turn off sprites 1, 3 and 5 we get no cycles back
  525. from the VIC. So in time-critical raster routines, always use sprites in
  526. order.
  527.  
  528.  
  529. _What can we do with this feature ?_
  530.  
  531. How can this be useful? A good use is for synchronization. Normally,
  532. before the CPU starts to execute the raster interrupt code, it's executing
  533. an instruction of undefined cycle-length. This execution time varies from
  534. two to seven cycles.
  535.  
  536. With a sprite, you can do the synchronization with a minimal effort using
  537. a DEC or INC instruction in the right place. If the processor is early,
  538. it has to wait for the bus, otherwise it will continue to execute cycles
  539. from the instruction.
  540.  
  541. I have never experimented with any other instruction than DEC/INC, but
  542. some others should work also. You need an instruction which has a cycle that
  543. do not need the bus to be available. e.g. INC $3fff will increase the
  544. value during the fifth cycle and do not need the bus for that.
  545.  
  546.  
  547. _A demo program_
  548.  
  549. The enclosed program includes a short raster color routine to demonstrate
  550. this strict timing and synchronization. The background color is changed
  551. 12 times on each line. The electron beam runs over eight pixels during
  552. one cycle, so the timing must be precise.
  553.  
  554. --------------------------------------------------------------------------
  555. _Table for PAL VIC timing for the Missing cycles_
  556.  
  557.  
  558. 012345678901234567890123456789012345678901234567890123456789012 cycles
  559.  
  560. Normal scan line, 0 sprites
  561. ggggggggggggggggggggggggggggggggggggggggrrrrr  p p p p p p p p  phi-1 VIC
  562.                                                                 phi-2 VIC
  563. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx phi-2 6510
  564. 63 cycles available
  565.  
  566. Normal scan line, 8 sprites
  567. ggggggggggggggggggggggggggggggggggggggggrrrrr  pspspspspspspsps phi-1 VIC
  568.                                                ssssssssssssssss phi-2 VIC
  569. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXX                 phi-2 6510
  570. 46-49 cycles available
  571.  
  572. Normal scan line, 4 sprites
  573. ggggggggggggggggggggggggggggggggggggggggrrrrr  psp psp psp psp  phi-1 VIC
  574.                                                ss  ss  ss  ss   phi-2 VIC
  575. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXXX              xx phi-2 6510
  576. 48-51 cycles available
  577.  
  578. Bad scan line, 0 sprites
  579. ggggggggggggggggggggggggggggggggggggggggrrrrr  p p p p p p p p  phi-1 VIC
  580. cccccccccccccccccccccccccccccccccccccccc                        phi-2 VIC
  581.                                         xxxxxxxxxxxxxxxxxxxxxxx phi-2 6510
  582. 23 cycles available
  583.  
  584. Bad scan line, 8 sprites
  585. ggggggggggggggggggggggggggggggggggggggggrrrrr  pspspspspspspsps phi-1 VIC
  586. cccccccccccccccccccccccccccccccccccccccc       ssssssssssssssss phi-2 VIC
  587.                                         xxxxXXX                 phi-2 6510
  588. 4-7 cycles available
  589.  
  590.  
  591. g= grafix data fetch (character images or graphics data)
  592. r= refresh
  593. p= sprite image pointer fetch
  594. c= character and color CODE fetch during a bad scan line
  595. s= sprite data fetch
  596. x= processor executing instructions
  597. X= processor executing an instruction, bus request pending
  598.  
  599. Observe! The left edge of the chart is not the left edge of the screen nor
  600.          the left edge of the beam, but the sprite x-coordinate 0. If you
  601.          have opened the borders, you know what I mean. A sprite can be
  602.          moved left from the coordinate 0 by using x-values greater than 500.
  603.  ___________
  604. |  _______  |<-- Maximum sized video screen
  605. |||       | |
  606. |||       |<-- Normal C64 screen
  607. |||       | |
  608. |||_______| |
  609. ||          |
  610. ||__________|
  611.  ^ Sprite coordinate 0
  612.  
  613.  
  614. --------------------------------------------------------------------------
  615. Demonstration program for missing cycles
  616.  
  617.  
  618. COLOR0= $CE00  ; Place for color bar 0
  619. COLOR1= $CF00  ; Place for color bar 1
  620. RASTER= $FA    ; Line for the raster interrupt
  621. DUMMY= $CFFF   ; Timing variable
  622.  
  623. *= $C000
  624.         SEI             ; Disable interrupts
  625.         LDA #$7F        ; Disable timer interrupts
  626.         STA $DC0D
  627.         LDA #$01        ; Enable raster interrupts
  628.         STA $D01A
  629.         STA $D015       ; Enable Sprite 0
  630.         LDA #<IRQ       ; Init interrupt vector
  631.         STA $0314
  632.         LDA #>IRQ
  633.         STA $0315
  634.         LDA #$1B
  635.         STA $D011
  636.         LDA #RASTER     ; Set interrupt position (inc. 9th bit)
  637.         STA $D012
  638.         LDA #RASTER-20  ; Sprite will just reach the interrupt position
  639.         STA $D001       ;  when it is positioned 20 lines earlier
  640.  
  641.         LDX #51
  642.         LDY #0
  643.         STA $D017       ; No Y-enlargement
  644. LOOP0   LDA COL,X       ; Create color bars
  645.         PHA
  646.         AND #15
  647.         STA COLOR0,X
  648.         STA COLOR0+52,Y
  649.         STA COLOR0+104,X
  650.         STA COLOR0+156,Y
  651.         PLA
  652.         LSR
  653.         LSR
  654.         LSR
  655.         LSR
  656.         STA COLOR1,X
  657.         STA COLOR1+52,Y
  658.         STA COLOR1+104,X
  659.         STA COLOR1+156,Y
  660.         INY
  661.         DEX
  662.         BPL LOOP0
  663.         CLI             ; Enable interrupts
  664.         RTS             ; Return
  665.  
  666.  
  667. IRQ     NOP             ; Wait a bit
  668.         NOP
  669.         NOP
  670.         NOP
  671.         LDY #103        ; 104 lines of colors (some of them not visible)
  672.                         ; Reduce for NTSC, 55 ?
  673.         INC DUMMY       ; Handles the synchronization with the help of the
  674.         DEC DUMMY       ;  sprite and the 6-clock instructions
  675.                         ; Add a NOP for NTSC
  676.  
  677. FIRST   LDX COLOR0,Y    ; Do the color effects
  678. SECOND  LDA COLOR1,Y
  679.         STA $D020
  680.         STX $D020
  681.         STA $D020
  682.         STX $D020
  683.         STA $D020
  684.         STX $D020
  685.         STA $D020
  686.         STX $D020
  687.         STA $D020
  688.         STX $D020
  689.         STA $D020
  690.         STX $D020
  691.                         ; Add a NOP for NTSC (one line = 65 cycles)
  692.         LDA #0          ; Throw away 2 cycles (total loop = 63 cycles)
  693.         DEY
  694.         BPL FIRST       ; Loop for 104 lines
  695.  
  696.         STA $D020
  697.         LDA #103        ; For subtraction
  698.         DEC FIRST+1     ; Move the bars
  699.         BPL OVER
  700.         STA FIRST+1
  701. OVER    SEC
  702.         SBC FIRST+1
  703.         STA SECOND+1
  704.  
  705.         LDA #1          ; Ack the raster interrupt
  706.         STA $D019
  707.         JMP $EA31       ; Jump to the standard irq handler
  708.  
  709. COL     BYT $09,$90,$09,$9B,$00,$99,$2B,$08,$90,$29,$8B,$08,$9C,$20,$89,$AB
  710.         BYT $08,$9C,$2F,$80,$A9,$FB,$08,$9C,$2F,$87,$A0,$F9,$7B,$18,$0C,$6F
  711.         BYT $07,$61,$40,$09,$6B,$48,$EC,$0F,$67,$41,$E1,$30,$09,$6B,$48,$EC
  712.         BYT $3F,$77,$11,$11
  713.                         ; Two color bars
  714.  
  715. --------------------------------------------------------------------------
  716. Basic loader for Missing cycles example program (PAL)
  717.  
  718. 1 S=49152
  719. 2 DEFFNH(C)=C-48+7*(C>64)
  720. 3 CH=0:READA$,A:PRINTA$:IFA$="END"THENPRINT"<clr>":SYS49152:END
  721. 4 FORF=0TO31:Q=FNH(ASC(MID$(A$,F*2+1)))*16+FNH(ASC(MID$(A$,F*2+2)))
  722. 5 CH=CH+Q:POKES,Q:S=S+1:NEXT:IFCH=ATHEN3
  723. 6 PRINT"CHECKSUM ERROR":END
  724. 100 DATA 78A97F8D0DDCA9018D1AD08D15D0A9578D1403A9C08D1503A91B8D11D0A9FA8D, 3773
  725. 101 DATA 12D0A9E68D01D0A233A0008D17D0BDACC048290F9D00CE9934CE9D68CE999CCE, 4157
  726. 102 DATA 684A4A4A4A9D00CF9934CF9D68CF999CCFC8CA10D95860EAEAEAEAA067EEFFCF, 4878
  727. 103 DATA CEFFCFBE18CEB94FCF8D20D08E20D08D20D08E20D08D20D08E20D08D20D08E20, 4403
  728. 104 DATA D08D20D08E20D08D20D08E20D0A9008810D18D20D0A967CE64C010038D64C038, 3923
  729. 105 DATA ED64C08D67C0EE19D04C31EA0990099B00992B0890298B089C2089AB089C2F80, 3483
  730. 106 DATA A9FB089C2F87A0F97B180C6F076140096B48EC0F6741E130096B48EC3F771111, 3133
  731. 200 DATA END,0
  732.  
  733. --------------------------------------------------------------------------
  734. Uuencoded C64 executable version (PAL)
  735.  
  736. begin 644 missing.64
  737. M`0@-"`$`4[(T.3$U,@`F"`(`EJ5(*$,ILD.K-#BJ-ZPH0[$V-"D`40@#`$-(?
  738. MLC`ZAT$D+$$ZF4$D.HM!)+(B14Y$(J>9(I,B.IXT.3$U,CJ``(@(!`"!1K(P/
  739. MI#,Q.E&RI4@HQBC**$$D+$:L,JHQ*2DIK#$VJJ5(*,8HRBA!)"Q&K#*J,BDI:
  740. M*0"I"`4`0TBR0TBJ43J74RQ1.E.R4ZHQ.H(ZBT-(LD&G,P#!"`8`F2)#2$5#F
  741. M2U-532!%4E)/4B(Z@``."60`@R`W.$$Y-T8X1#!$1$-!.3`Q.$0Q040P.$0QK
  742. M-40P03DU-SA$,30P,T$Y0S`X1#$U,#-!.3%".$0Q,40P03E&03A$+"`S-S<SA
  743. M`%L)90"#(#$R1#!!.44V.$0P,40P03(S,T$P,#`X1#$W1#!"1$%#0S`T.#(Y?
  744. M,$8Y1#`P0T4Y.3,T0T4Y1#8X0T4Y.3E#0T4L(#0Q-3<`J`EF`(,@-C@T031!4
  745. M-$$T03E$,#!#1CDY,S1#1CE$-CA#1CDY.4-#1D,X0T$Q,$0Y-3@V,$5!14%%>
  746. M045!03`V-T5%1D9#1BP@-#@W.`#U"6<`@R!#149&0T9"13$X0T5".31&0T8X^
  747. M1#(P1#`X13(P1#`X1#(P1#`X13(P1#`X1#(P1#`X13(P1#`X1#(P1#`X13(PH
  748. M+"`T-#`S`$(*:`"#($0P.$0R,$0P.$4R,$0P.$0R,$0P.$4R,$0P03DP,#@XV
  749. M,3!$,3A$,C!$,$$Y-C=#138T0S`Q,#`S.$0V-$,P,S@L(#,Y,C,`CPII`(,@^
  750. M140V-$,P.$0V-T,P144Q.40P-$,S,45!,#DY,#`Y.4(P,#DY,D(P.#DP,CDX[
  751. M0C`X.4,R,#@Y04(P.#E#,D8X,"P@,S0X,P#<"FH`@R!!.49",#@Y0S)&.#=!?
  752. M,$8Y-T(Q.#!#-D8P-S8Q-#`P.39"-#A%0S!&-C<T,44Q,S`P.39"-#A%0S-&V
  753. ;-S<Q,3$Q+"`S,3,S`.@*R`"#($5.1"PP````8
  754. ``
  755. end
  756. size 747
  757.  
  758. --------------------------------------------------------------------------
  759. Uuencoded C64 executable version (NTSC)
  760.  
  761. begin 644 missing.64
  762. M`0@-"`$`4[(T.3$U,@`F"`(`EJ5(*$,ILD.K-#BJ-ZPH0[$V-"D`40@#`$-(?
  763. MLC`ZAT$D+$$ZF4$D.HM!)+(B14Y$(J>9(I,B.IXT.3$U,CJ``(@(!`"!1K(P/
  764. MI#,Q.E&RI4@HQBC**$$D+$:L,JHQ*2DIK#$VJJ5(*,8HRBA!)"Q&K#*J,BDI:
  765. M*0"I"`4`0TBR0TBJ43J74RQ1.E.R4ZHQ.H(ZBT-(LD&G,P#!"`8`F2)#2$5#F
  766. M2U-532!%4E)/4B(Z@``."60`@R`W.$$Y-T8X1#!$1$-!.3`Q.$0Q040P.$0QK
  767. M-40P03DU-SA$,30P,T$Y0S`X1#$U,#-!.3%".$0Q,40P03E&03A$+"`S-S<SA
  768. M`%L)90"#(#$R1#!!.44V.$0P,40P03(S,T$P,#`X1#$W1#!"1$%%0S`T.#(YA
  769. M,$8Y1#`P0T4Y.3,T0T4Y1#8X0T4Y.3E#0T4L(#0Q-3D`J`EF`(,@-C@T031!6
  770. M-$$T03E$,#!#1CDY,S1#1CE$-CA#1CDY.4-#1D,X0T$Q,$0Y-3@V,$5!14%%>
  771. M045!03`S-T5%1D9#1BP@-#@S,`#U"6<`@R!#149&0T9%04)%,#!#14(Y,#!#4
  772. M1CA$,C!$,#A%,C!$,#A$,C!$,#A%,C!$,#A$,C!$,#A%,C!$,#A$,C!$,#A%$
  773. M+"`T-3`R`$(*:`"#(#(P1#`X1#(P1#`X13(P1#`X1#(P1#`X13(P1#!%04$Y.
  774. M,#`X.#$P1#`X1#(P1#!!.38W0T4V-4,P,3`P,SA$-C4L(#,Y-#(`CPII`(,@R
  775. M0S`S.$5$-C5#,#A$-CA#,$5%,3E$,#1#,S%%03`Y.3`P.3E",#`Y.3)",#@Y(
  776. M,#(Y.$(P.#E#,C`X.4%",#@Y0RP@,S4U.`#<"FH`@R`R1C@P03E&0C`X.4,R_
  777. M1C@W03!&.3=",3@P0S9&,#<V,30P,#DV0C0X14,P1C8W-#%%,3,P,#DV0C0XK
  778. M14,S1C<W+"`S,C<T`"<+:P"#(#$Q,3$P,#`P,#`P,#`P,#`P,#`P,#`P,#`PO
  779. M,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`L(#,T`#,+1
  780. ,;`"#($5.1"PP````"
  781. ``
  782. end
  783. size 822
  784.  
  785. ============================================================================
  786. Kernal 64 / 128 
  787. by Craig Taylor (duck@pembvax1.pembroke.edu)
  788.  
  789.                              +--------------+
  790.                              | Introduction |
  791.                              +--------------+
  792.  
  793.   When Commodore introduced the PET ages ago before the Vic-20 and Commodore 64,
  794. 128 they set in the highest memory locations a series of jumps to other routines
  795. so that users didn't need bother checking if any revisions had been made. They
  796. were assured that the address they were jumping to, would indeed, be the address
  797. that would print out a character or whatnot.
  798.  
  799.   The KERNAL has grown since Commodore first introduced it, the C=128 KERNAL has
  800. fifty-seven seperate routines which are available to programmers. These routines
  801. handle functions relating to the serial devices (the bulk of them), the screen
  802. and miscellanous system routines such as scanning the keyboard, updating and
  803. reading the system clock (TI$).
  804.  
  805.                           +-------------------+
  806.                           | Table of Routines |
  807.                           +-------------------+
  808.  
  809.   The following table lists the available routines, their function, address,
  810. their name, and registers affected upon exit. In addation, on the left of each
  811. line are the group that I have catagorized them under: Video(Vid), System(Sys),
  812. and Serial(Ser).
  813.  
  814. --------+---------+---------+---------------------------------------+-----------
  815.         |         |Registers|                                       |Group
  816. Address | NAME    | A X Y F | Descritption                          |Vid Sys Ser
  817. --------+---------+---------+---------------------------------------+-----------
  818. FF47/128|SPINSPOUT| *       | Initializes I/O for fast serial       |        ***
  819. FF4A/128| CLOSEALL| * * *   | Close all files on a device           |        ***
  820. FF4D/128| C64MODE |         | Switches to C=64 mode                 |    *** 
  821. FF50/128| DMACALL | * *     | Send DMA command to REU               |    ***
  822. FF53/128| BOOTCALL| * *   * | Attempts to run boot sector           |    *** ***
  823. FF56/128| PHOENIX | * * *   | Initalizes external/internal cartri.  |    ***
  824. FF59/128| LKUPLA  | * * * * | Looks up logical device #             |    *** ***
  825. FF5C/128| LKUPSA  | * * * * | Looks up for secondary address        |    *** ***
  826. FF5F/128| SWAPPER | * * *   | Switches betten 40 / 80 column screen |*** 
  827. FF62/128| DLCHAR  | * * *   | Initializes 80 column character set   |***
  828. FF65/128| PFKEY   | * * * * | Installs a function key definition    |    ***
  829. FF68/128| SETBNK  |         | Sets bank for any I/O operations      |    *** ***
  830. FF6B/128| GETCFG  | *       | Get MMU configuration for a given bank|    ***
  831. FF6E/128| JSRFAR  |         | Jumps to a subroutine in another bank |    ***
  832. FF71/128| JMPFAR  |         | Starts executing code in another bank |    ***
  833. FF74/128| INDFET  | * *   * | Execute a LDA(fetvec),Y from a bank   |    ***
  834. FF77/128| INDSTA  |   *   * | Stores a value indirectly in a bank   |    ***
  835. FF7A/128| INDCMP  |   *   * | Compares a value indirectly in a bank |    ***
  836. FF7D/128| PRIMM   |         | Outputs null-terminated string        |***     ***
  837. ////////|/////////|/////////|///////////////////////////////////////|///////////
  838. FF81    | CINT    | * * *   | Setup VIC,screen values, 8563...      |*** 
  839. FF84    | IOINIT  | * * *   | Initialize VIC,SID,8563,CIA for system|*** ***
  840. FF87    | RAMTAS  | * * *   | Initialize ram.                       |    ***
  841. FF8D    | VECTOR  | *   *   | Reads or Writes to Kernal RAM Vectors |    ***
  842. FF90    | SETMSG  |         | Sets Kernal Messages On/Off.          |    ***
  843. FF93    | SECND   | *       | Sends secondary address after LISTN   |    *** ***
  844. FF96    | TKSA    | *       | Sends secondary address after TALK    |    *** ***
  845. FF99    | MEMTOP  |   * *   | Read or set the top of system RAM.    |    ***
  846. FF9C    | MEMBOT  |   * *   | Read or set the bottom of system RAM. |    ***
  847. FF9F    | KEY     |         | Scans Keyboard                        |    ***
  848. FFA2    | SETMO   |         | -- Unimplemented Subroutine in All -- |   [N/A]
  849. FFA5    | ACPTR   | *       | Grabs byte from current talker        |    *** ***
  850. FFA8    | CIOUT   | *       | Output byte to current listener       |    *** ***
  851. FFAB    | UNTLK   | *       | Commands device to stop talking       |    *** ***
  852. FFAE    | UNLSN   | *       | Commands device to stop listening     |    *** ***
  853. FFB1    | LISTN   | *       | Commands device to begin listening    |    *** ***
  854. FFB4    | TALK    | *       | Commands device to begin talking      |    *** ***
  855. FFB7    | READSS  | *       | Returns I/O status byte               |        ***
  856. FFBA    | SETLFS  |         | Sets logical #, device #, secondary # |        ***
  857. FFBD    | SETNAM  |         | Sets pointer to filename.             |        ***
  858. FFC0    | OPEN    | * * * * | Opens up a logical file.              |        ***
  859. FFC3    | CLOSE   | * * * * | Closes a logical file.                |        ***
  860. FFC6    | CHKIN   | * * * * | Set input channel                     |        ***
  861. FFC9    | CHKOUT  | * * * * | Set output channel                    |        ***
  862. FFCC    | CLRCH   | * *     | Restore default channels              |        ***
  863. FFCF    | BASIN   | *     * | Input from channel                    |        ***
  864. FFD2    | BSOUT   | *     * | Output to channel (aka CHROUT)        |***     ***
  865. FFD5    | LOAD    | * * * * | Load data from file                   |        ***
  866. FFD8    | SAVE    | * * * * | Save data to file                     |        ***
  867. FFDB    | SETTIM  |         | Sets internal (TI$) clock             |    *** 
  868. FFDE    | RDTIM   | * * *   | Reads internal (TI$) clock            |    ***
  869. FFE1    | STOP    | * *     | Scans and check for STOP key          |    ***
  870. FFE4    | GETIN   | * * * * | Reads buffered data from file         |        ***
  871. FFE7    | CLALL   | * *     | Close all open files and channels     |        ***
  872. FFEA    | UDTIM   | * *     | Updates internal (TI$) clock          |    ***
  873. FFED    | SCRORG  | * * *   | Returns current window/screen size    |*** 
  874. FFF0    | PLOT    |   * * * | Read or set cursor position           |***
  875. FFF3    | IOBASE  |   * *   | Read base of I/O block                |    ***
  876. --------+---------+---------+---------------------------------------+-----------
  877.                           
  878.                           +--------------------------+
  879.                           | The Routines Themselves. |
  880.                           +--------------------------+
  881.  
  882. A. Error handling
  883.  
  884.   For the routines in the KERNAL that return status codes (indicated by the FL
  885. status in the chart) the carry is set if there is an error.  Otherwise, the 
  886. carry returned is clear.  If the carry is set, the error code is returned in the
  887. accumalator:
  888.                                            +-----------------------------------+
  889.        .A |Meaning                         | NOTE: Some of the I/O routines    |
  890.       ----+------------------------------  |       indicate the error code via |
  891.         0 | Stop Key pressed               |       the READST routine when     |
  892.         1 | Too Many Open Files            |       setting the carry.          |
  893.         2 | File Already Open              +------------------------------------
  894.         3 | File Not Open
  895.         4 | File Not Found
  896.         5 | Device Not Present
  897.         6 | File Was Not Opened As Input
  898.         7 | File Was Not Opened As Output
  899.         8 | File Name Not Present
  900.         9 | Illegal Device Number
  901.        41 | File Read Error
  902.  
  903.  
  904. B. Device Numbers:
  905.  
  906.   The following table lists the "standard" device numbers used by the C= Kernal.
  907.            +---------+----------------------------+
  908.            |Device # | Device Name                |
  909.            +---------+----------------------------+
  910.            |   0     | Keyboard (standard input)  |
  911.            |   1     | Cassette                   |
  912.            |   2     | RS-232                     |
  913.            |   3     | Screen   (standard output) |
  914.            |   4 - 30| Serial Bus Devices         |
  915.            |     4-7 | Printers        (typically)|
  916.            |     8-30| Disk Drives     (typically)|
  917.            +---------+----------------------------+
  918.  
  919. C. Routine Descriptions.
  920.  
  921.   Due to space limitations a fully-detailed, descriptive summary of the KERNAL
  922. routines is not feasible.  However, listed below is a description of what each
  923. routine does, expected parameters and any notes on C=128/C=64 differences as 
  924. well as notes to clarify any possibly confusing details.
  925.  
  926.  ---------------------------------------------------------------------------
  927.  
  928. Routine        : SPINSPOUT ** 128 ONLY **
  929.  Kernal Address: $FF47
  930.  Description   : Setup CIA for BURT protocol.
  931.  Registers In  : .C = 0 -> SPINP (input)
  932.                  .C = 1 -> SPOUT (output)
  933.  Registers Out : .A destroyed
  934.  Memory Changed: CIA, MMU.
  935.  
  936. Routine        : CLOSEALL ** 128 ONLY **
  937.  Kernal Address: $FF4A
  938.  Description   : Close all files on a device.
  939.  Registers In  : .A = device # (0-31)
  940.  Registers Out : .A, .X, .Y used.
  941.  Memory Changed: None.
  942.  
  943. Routine        : C64MODE ** 128 ONLY **
  944.  Kernal Address: $FF4D
  945.  Description   : Switches to C64 Mode
  946.  Registers In  : None.
  947.  Registers Out : None.
  948.  Memory Changed: -ALL- This routine initializes and calls the C64 cold start
  949.                  routine. There is no way to switch out of C64 mode once this
  950.                  routine is entered.
  951.  
  952. Routine        : DMACALL ** 128 ONLY **
  953.  Kernal Address: $FF50
  954.  Description   : Perform DMA command (for REU)
  955.  Registers In  : .X = Bank, .Y = DMA controller command
  956.                  NOTE: REU registers must have been previously setup.
  957.  Registers Out : .A, .X used
  958.  Memory Changed: Dependenant upon REU registers, REU command.
  959.  
  960. Routine        : BOOTCALL ** 128 ONLY **
  961.  Kernal Address: $FF53
  962.  Description   : Attempts to load and execute boot sector from a drive.
  963.  Registers In  : .A = drive # in ascii (usually '0' / $30)
  964.                  .X = device #
  965.  Registers Out : .A, .X, .Y used. .C = 1 if I/O error.
  966.  Memory Changed: As per boot sector. 
  967.  
  968. Routine        : PHOENIX ** 128 ONLY **
  969.  Kernal Address: $FF56
  970.  Description   : Initalizes external / internatal cartridges,check for disk boot
  971.  Registers In  : None.
  972.  Registers Out : .A, .X, .Y used.
  973.  Memory Changed: Calls any auto-start catridges that are installed on the system
  974.  
  975. Routine        : LKUPLA ** 128 ONLY **
  976.  Kernal Address: $FF59
  977.  Description   : Search file tables for a given logical device #.
  978.  Registers In  : .A = Logical Device #.
  979.  Registers Out : .C = 0 if found -> .A = Logical Device #, 
  980.                                     .X = Logical File #,
  981.                                     .Y = Logical Secondary #.
  982.                  .C =1 if not found.
  983.  Memory Changed: None.
  984.  
  985. Routine        : LKUPSA ** 128 ONLY **
  986.  Kernal Address: $FF5C
  987.  Description   : Search file tables for a given secondary address.
  988.  Registers In  : .Y = Secondary address to search for.
  989.  Registers Out : As LKUPLA (see LKUPLA).
  990.  Memory Changed: None.
  991.  
  992. Routine        : SWAPPER ** 128 ONLY **
  993.  Kernal Address: $FF5F
  994.  Description   : Switches between 40 / 80 column screen.
  995.  Registers In  : None.
  996.  Registers Out : .A, .X, .Y destroyed.
  997.  Memory Changed: Screen Editor Locations.
  998.  
  999. Routine        : DLCHAR ** 128 ONLY **
  1000.  Kernal Address: $FF62
  1001.  Description   : Initializes 80 column character set.
  1002.  Registers In  : None.
  1003.  Registers Out : .A, .X, .Y destroyed.
  1004.  Memory Changed: None.
  1005.  
  1006. Routine        : PFKEY ** 128 ONLY **
  1007.  Kernal Address: $FF65
  1008.  Description   : Installs a function key definition      
  1009.  Registers In  : .A = pointer to Z-P address (3 bytes : address lo/hi/bank.)
  1010.                  .Y = length, .X = key # (9 = Shift RUN/STOP, 10 = HELP).
  1011.  Registers Out : .C = 1 if No room, .C = 0 if successful.
  1012.                  .A, .X, .Y destroyed.
  1013.  Memory Changed: Function Key Table modified.
  1014.  
  1015. Routine        : SETBNK ** 128 ONLY **
  1016.  Kernal Address: $FF68
  1017.  Description   : Sets bank for any future I/O operations
  1018.  Registers In  : .A = Memory Bank, .X = Bank where filename is.
  1019.  Registers Out : None.
  1020.  Memory Changed: None.
  1021.  
  1022. Routine        : GETCFG ** 128 ONLY **
  1023.  Kernal Address: $FF6B
  1024.  Description   : Get MMU configuration for a given bank.
  1025.  Registers In  : None.
  1026.  Registers Out : None.
  1027.  Memory Changed: 
  1028.  
  1029. Routine        : JSRFAR ** 128 ONLY **
  1030.  Kernal Address: $FF6E
  1031.  Description   : Jumps to a subroutine in another bank.
  1032.  Registers In  : None. (See JMPFAR for mem locations IN)
  1033.  Registers Out : None. (See JMPFAR for mem locations OUT)
  1034.  
  1035. Routine        : JMPFAR ** 128 ONLY **
  1036.  Kernal Address: $FF71
  1037.  Description   : Starts executing code in another bank.  
  1038.  Registers In  : None.
  1039.    Memory In   :  $02 - Bank (0-15)
  1040.                   $03 - PC high
  1041.                   $04 - PC lo
  1042.                   $05 - .S (Processor status)
  1043.                   $06 - .A
  1044.                   $07 - .X
  1045.                   $08 - .Y
  1046.  Registers Out : None.
  1047.    Memory Out  : As memory in.
  1048.  
  1049. Routine        : INDFET ** 128 ONLY **
  1050.  Kernal Address: $FF74
  1051.  Description   : Execute a LDA(fetvec),Y from a bank.
  1052.  Registers In  : .A - pointer to Z-Page location holding address
  1053.                  .X - Bank (0-15), .Y - Index.
  1054.  Registers Out : .A = data, .X - destroyed.
  1055.  Memory Changed: None.
  1056.  
  1057. Routine        : INDSTA ** 128 ONLY **
  1058.  Kernal Address: $FF77
  1059.  Description   : Execute a STA(stavec),Y in a bank.
  1060.  Registers In  : .A - pointer to Z-Page location holding address
  1061.                  .X - Bank (0-15), .Y - Index.
  1062.  Registers Out : .X - Destroyed.
  1063.  Memory Changed: As per registers.
  1064.  
  1065. Routine        : INDCMP ** 128 ONLY **
  1066.  Kernal Address: $FF7A
  1067.  Description   : Executes a CMP(cmpvec),Y in a bank.
  1068.  Registers In  : .A = data, .X = Bank (0-15), .Y - Z-Page ptr.
  1069.  Registers Out : .X destroyed, Flags set accordingly.
  1070.  Memory Changed: None.
  1071.  
  1072. Routine        : PRIMM ** 128 ONLY **
  1073.  Kernal Address: $FF7D
  1074.  Description   : Prints null terminated string following JSR to current channel
  1075.  Registers In  : None.
  1076.  Registers Out : None.
  1077.  Memory Changed: Dependent upon current device. 
  1078.  Example       :
  1079.                [ . . . ]
  1080.                  JSR $FF7D         ; JSR to primm, / print following string.
  1081.                  .ASC "Hi World!"  ; String to print.
  1082.                  .BYT $00          ; IMPORTANT: Null Terminated.
  1083.                [ . . . ]
  1084.  
  1085.  ---------------------------------------------------------------------------
  1086.  
  1087. Routine        : CINT
  1088.  Kernal Address: $FF81
  1089.  Description   : Setup VIC, screen values, (128: 8563)...
  1090.  Registers In  : None.
  1091.  Registers Out : None.
  1092.  Memory Changed: Screen Editor Locations.
  1093.  
  1094. Routine        : IOINIT
  1095.  Kernal Address: $FF84
  1096.  Description   : Initializes pertinant display and i/o devices
  1097.  Registers In  : C64: None. | C128: $0A04/bit 7
  1098.                             |          0 - Full Setup.
  1099.                             |          1 - Partial Setup. (no 8563 char)
  1100.  Registers Out : .A, .X, .Y destroyed.
  1101.  Memory Changed: CIA's, VIC, 8502 port, (C128: also optionally 8563).
  1102.  Note          : This routine automatically distinguishes a PAL system from a
  1103.                  NTSC system and sets PALCNT accordingly for use in the 
  1104.                  time routines.
  1105.  
  1106. Routine        : RAMTAS
  1107.  Kernal Address: $FF87
  1108.  Description   : Clears Z-Page, Sets RS-232 buffers, top/bot Ram.
  1109.  Registers In  : None.
  1110.  Registers Out : .A, .X, .Y destroyed.
  1111.  Memory Changed: Z-Page, Rs-232 buffers, top/bot Ram ptrs
  1112.  
  1113. Routine        : VECTOR
  1114.  Kernal Address: $FF8D
  1115.  Description   : Copies / Stores KERNAL indirect RAM vectors.
  1116.  Registers In  : .C = 0 (Set KERNAL Vectors) | .C = 1 (Duplicate KERNAL vectors)
  1117.                  .XY = address of vectors    | .XY = address of user vectors
  1118.  Registers Out : .A, .Y destroyed            | .A, .Y destroyed.
  1119.  Memory Changed: KERNAL Vectors changed      | Vectors written to .XY
  1120.  Note          : This routine is rarely used, usually the vectors are directly
  1121.                  changed themselves. The vectors, in order, are :
  1122.  
  1123.                  C128: IRQ,BRK,NMI,OPEN,CLOSE,CHKIN,CHKOUT,CLRCH,BASIN,BSOUT
  1124.                        STOP,GETIN,CLALL,EXMON (monitor),LOAD,SAVE
  1125.                  C64 : IRQ,BRK,NMI,OPEN,CLOSE,CHKIN,CHKOUT,CLRCH,BASIN,BSOUT
  1126.                        STOP,GETIN,CLALL,USRCMD (not used),LOAD,SAVE
  1127.  
  1128. Routine        : SETMSG
  1129.  Kernal Address: $FF90
  1130.  Description   : Set control of KERNAL control and error messages.
  1131.  Registers In  : .A bit 7 = KERNAL Control Messages (1 = on)
  1132.                     bit 6 = KERNAL Error   Messages (1 = on)
  1133.  Registers Out : None.
  1134.  Note          : KERNAL Control messages are those defined as Loading, Found etc
  1135.                  ... KERNAL Error messages are I/O ERROR # messages which are
  1136.                  listed as follows:
  1137.  
  1138. Routine        : SECND
  1139.  Kernal Address: $FF93
  1140.  Description   : Sends secondary address to device after a LISTN
  1141.  Registers In  : .A = secondary address
  1142.  Registers Out : .A used.
  1143.  Memory Changed: None.
  1144.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1145.  
  1146. Routine        : TKSA
  1147.  Kernal Address: $FF96
  1148.  Description   : Sends secondary address to device after TALK
  1149.  Registers In  : .A = secondary address.
  1150.  Registers Out : .A used.
  1151.  Memory Changed: None.
  1152.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1153.  
  1154. Routine        : MEMTOP
  1155.  Kernal Address: $FF99
  1156.  Description   : Read or Set top of System Ram
  1157.  Registers In  : .C = 1 (Read MemTop)     | .C = 0 (Set MemTop)
  1158.                                           | .XY = top of memory
  1159.  Registers Out : .XY = top of memory      | None.
  1160.  Memory Changed: None.                    | Top of memory changed.
  1161.  Note          : On the C=128, this routine refers to the top of BANK 0 RAM, not
  1162.                  BANK 1 RAM.
  1163.  
  1164. Routine        : MEMBOT
  1165.  Kernal Address: $FF9C
  1166.  Description   : Read or Set bottom of System Ram
  1167.  Registers In  : .C = 1 (Read MemBot)     | .C = 0 (Set MemBot)
  1168.                                           | .XY = bottom of memory.
  1169.  Registers Out : .XY = bottom of memory   | None.
  1170.  Memory Changed: None.                    | Bottom of Memory changed.
  1171.  Note          : On the C=128, this routine refers to the bottom of BANK 0 RAM,
  1172.                  not, BANK 1 RAM.
  1173.  
  1174. Routine        : KEY
  1175.  Kernal Address: $FF9F
  1176.  Description   : Scans Keyboard
  1177.  Registers In  : None.
  1178.  Registers Out : None.
  1179.  Memory Changed: Relevant System Keyboard Values
  1180.  
  1181. Routine        : SETMO
  1182.  Kernal Address: $FFA2
  1183.  Description   : This is a routine who's code never made it into any versions
  1184.                  of the KERNAL on the C64, Vic-20 and C128.  Thus it is of no
  1185.                  pratical use.
  1186.  
  1187. Routine        : ACPTR
  1188.  Kernal Address: $FFA5
  1189.  Description   : Get byte from current talker.
  1190.  Registers In  : None.
  1191.  Registers Out : .A = data byte.
  1192.  Memory Changed: None.
  1193.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1194.  
  1195. Routine        : CIOUT
  1196.  Kernal Address: $FFA8
  1197.  Description   : Output byte to current listener.
  1198.  Registers In  : .A = byte.
  1199.  Registers Out : .A used.
  1200.  Memory Changed: None.
  1201.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1202.  
  1203. Routine        : UNTLK
  1204.  Kernal Address: $FFAB
  1205.  Description   : Commands current TALK device to stop TALKING.
  1206.  Registers In  : None.
  1207.  Registers Out : .A used.
  1208.  Memory Changed: None.
  1209.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1210.  
  1211. Routine        : UNLSN
  1212.  Kernal Address: $FFAE
  1213.  Description   : Commands current listening device to stop listening.
  1214.  Registers In  : None.
  1215.  Registers Out : .A used.
  1216.  Memory Changed: None.
  1217.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1218.  
  1219. Routine        : LISTN
  1220.  Kernal Address: $FFB1
  1221.  Description   : Commands device to begin listening.
  1222.  Registers In  : .A = device #.
  1223.  Registers Out : .A used.
  1224.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1225.  
  1226. Routine        : TALK
  1227.  Kernal Address: $FFB4
  1228.  Description   : Commands device to begin talking.
  1229.  Registers In  : .A = device #.
  1230.  Registers Out : .A used.
  1231.  Memory Changed: None.
  1232.  Note          : Low level serial I/O - recommended use OPEN,CLOSE,CHROUT etc..
  1233.  
  1234. Routine        : READSS
  1235.  Kernal Address: $FFB7
  1236.  Description   : Return I/O status byte.
  1237.  Registers In  : None.
  1238.  Registers Out : .A = status byte. (see section on ERROR messages).
  1239.  Memory Changed: None.
  1240.  
  1241. Routine        : SETLFS
  1242.  Kernal Address: $FFBA
  1243.  Description   : Set logical file #, device #, secondary # for I/O.
  1244.  Registers In  : .A = logical file #, .X = device #, .Y = secondary #
  1245.  Registers Out : None.
  1246.  Memory Changed: None.
  1247.  
  1248. Routine        : SETNAM
  1249.  Kernal Address: $FFBD
  1250.  Description   : Sets pointer to filename in preperation for OPEN.
  1251.  Registers In  : .A = string length, .XY = string address.
  1252.  Registers Out : None.
  1253.  Memory Changed: None.
  1254.  Note          : To specify _no_ filename specify a length of 0.
  1255.  
  1256. Routine        : OPEN
  1257.  Kernal Address: $FFC0
  1258.  Description   : Open up file that has been setup by SETNAM,SETLFS
  1259.  Registers In  : None.
  1260.  Registers Out : .A = error code, .X,.Y destroyed.
  1261.                  .C = 1 if error.
  1262.  Memory Changed: None.
  1263.  
  1264. Routine        : CLOSE
  1265.  Kernal Address: $FFC3
  1266.  Description   : Close a logical file.
  1267.  Registers In  : .A = logical file #.
  1268.  Registers Out : .A = error code, .X,.Y destroyed.
  1269.                  .C = 1 if error
  1270.  Memory Changed: None.
  1271.  
  1272. Routine        : CHKIN
  1273.  Kernal Address: $FFC6
  1274.  Description   : Sets input channel.
  1275.  Registers In  : .X = logical file #.
  1276.  Registers Out : .A = error code, .X,.Y destroyed.
  1277.                  .C = 1 if error
  1278.  Memory Changed: None.
  1279.  
  1280. Routine        : CHKOUT
  1281.  Kernal Address: $FFC9
  1282.  Description   : Sets output channel.
  1283.  Registers In  : .X = logical file #.
  1284.  Registers Out : .A = error code, .X,.Y destroyed.
  1285.                  .C = 1 if error
  1286.  Memory Changed: None.
  1287.  
  1288. Routine        : CLRCH
  1289.  Kernal Address: $FFCC
  1290.  Description   : Restore default input and output channels.
  1291.  Registers In  : None.
  1292.  Registers Out : .A, .X used.
  1293.  Memory Changed: None.
  1294.  
  1295. Routine        : BASIN
  1296.  Kernal Address: $FFCF
  1297.  Description   : Read character from current input channel.
  1298.                  Cassette - Returned one character a time from cassette buffer.
  1299.                  Rs-232   - Return one character at a time, waiting until 
  1300.                             character is ready.
  1301.                  Serial   - Returned one character at time, waiting if nessc.
  1302.                  Screen   - Read from current cursor position.
  1303.                  Keyboard - Read characters as a string, then return them 
  1304.                             individually upon each call until all characters
  1305.                             have been passed ($0d is the EOL).
  1306.  Registers In  : None.
  1307.  Registers Out : .A = character or error code, .C = 1 if error.
  1308.  Memory Changed: None.
  1309.  
  1310. Routine        : BSOUT aka CHROUT
  1311.  Kernal Address: $FFD2
  1312.  Description   : Output byte to current channel
  1313.  Registers In  : .A = Byte
  1314.  Registers Out : .C = 1 if ERROR (examine READST)
  1315.  Memory Changed: Dependent upon current device.
  1316.  
  1317. Routine        : LOAD
  1318.  Kernal Address: $FFD5
  1319.  Description   : Loads file into memory (setup via SETLFS,SETNAM)..
  1320.  Registers In  : .A = 0 - Load, Non-0 = Verify
  1321.                  .XY = load address (if secondary address = 0)
  1322.  Registers Out : .A = error code .C = 1 if error.
  1323.                  .XY = ending address 
  1324.  Memory Changed: As per registers / data file.
  1325.  
  1326. Routine        : SAVE
  1327.  Kernal Address: $FFD8
  1328.  Description   : Save section of memory to a file.
  1329.  Registers In  : .A = Z-page ptr to start adress
  1330.                  .XY = end address
  1331.  Registers Out : .A = error code, .C = 1 if error.
  1332.                  .XY = used.
  1333.  Memory Changed: None.
  1334.  
  1335. Routine        : SETTIM
  1336.  Kernal Address: $FFDB
  1337.  Description   : Set internal clock (TI$).
  1338.  Registers In  : .AXY - Clock value in jiffies (1/60 secs).
  1339.  Registers Out : None.
  1340.  Memory Changed: Relevant system time locations set.
  1341.  
  1342. Routine        : RDTIM
  1343.  Kernal Address: $FFDE
  1344.  Description   : Reads internal clock (TI$)
  1345.  Registers In  : None.
  1346.  Registers Out : .AXY - Clock value in jiffies (1/60 secs).
  1347.  Memory Changed: None.
  1348.  
  1349. Routine        : STOP
  1350.  Kernal Address: FFE1
  1351.  Description   : Scans STOP key.
  1352.  Registers In  : None.
  1353.  Registers Out : .A = last keyboard row, .X = destroyed (if stop key)
  1354.  Memory Changed: None.
  1355.  Note          : The last keyboard row is as follows:
  1356.                  .A -> | 7   | 6   | 5   | 4   | 3   | 2   | 1  | 0
  1357.                   KEY: |STOP |Q    |C=   |SPACE|2    |CTRL |<-  |1
  1358.  
  1359. Routine       : GETIN
  1360.  Kernal Address: $FFE4
  1361.  Description   : Read buffered data from file.
  1362.                  Keyboard - Read from keyboard buffer, else return null ($00).
  1363.                  Rs-232   - Read from Rs-232 buffer, else null is returned.
  1364.                  Serial   - See BASIN
  1365.                  Cassette - See BASIN
  1366.                  Screen   - See BASIN
  1367.  Registers In  : None.
  1368.  Registers Out : .A = character, .C = 1 if error.
  1369.                  .XY = used.
  1370.  Memory Changed: None.
  1371.  
  1372. Routine       : CLALL
  1373.  Kernal Address: $FFE7
  1374.  Description   : Close all open files and channels.
  1375.  Registers In  : None.
  1376.  Registers Out : .AX used.
  1377.  Memory Changed: None.
  1378.  Note          : This routine does not _actually_ close the files, rather it
  1379.                  removes their prescense from the file tables held in memory.
  1380.                  It's recommended to use close to close files instead of using
  1381.                  this routine.
  1382.  
  1383.  
  1384. Routine        : UDTIME
  1385.  Kernal Address: $FFEA
  1386.  Description   : Update internal (TI$) clock by 1 jiffie (1/60 sec).
  1387.  Registers In  : None.
  1388.  Registers Out : .A,.X destroyed.
  1389.  Memory Changed: Relevant system time locations changed.
  1390.  
  1391. Routine        : SCRORG
  1392.  Kernal Address: $FFED
  1393.  Description   : Returns current window/screen size
  1394.  Registers In  : None.
  1395.  Registers Out : .X - Window Row Max
  1396.                  .Y - Window Col Max
  1397.                  .A - Screen Col Max (128 only, 64 unchanged)
  1398.  Memory Changed: None
  1399.  
  1400. Routine        : PLOT
  1401.  Kernal Address: $FFF0
  1402.  Description   : Read or set cursor position.
  1403.  Registers In  : .C = 1 (Read)        |      .C = 0 (Set)
  1404.                    None.              |        .X = Col
  1405.                                       |        .Y = Row
  1406.  Registers Out : .C = 1 (Read)        |      .C = 0 (Set) 
  1407.                    .X = Current Col   |         None.
  1408.                    .Y = Current Row   |
  1409.  Memory Changed:  None                |      Screen Editor Locations.
  1410.  
  1411. Routine        : IOBASE
  1412.  Kernal Address: $FFF3
  1413.  Description   : Returns base of I/O Block
  1414.  Registers In  : None.
  1415.  Registers Out : .XY = address of I/O block ($D000)
  1416.  Memory Changed: Screen Editor Locations.
  1417.  
  1418. ============================================================================
  1419. 64K VDC RAM and an alternate GEOS128 Background Screen
  1420. by Robert A. Knop Jr. (rknop@tybalt.caltech.edu, R.KNOP1 on GEnie)
  1421.  
  1422. I. Introduction
  1423.  
  1424. GEOS, both the 64 and 128 varieties, uses bitmapped screens for its output.
  1425. In 40 columns, this means 8K of system memory is set aside for the main
  1426. screen.  Then, in addition, GEOS also uses display buffering; in other words,
  1427. GEOS allocates a second 8K as a "background" (BG) screen that is used to keep
  1428. an intact copy of the foreground (FG) screen.  This can be very useful for a
  1429. number of reasons; one, it can be used as an undo buffer, as it is in
  1430. geoPaint.  When you have a delicate drawing, and then accidentally run the
  1431. eraser across it, the effects of the eraser are only written to the FG screen.
  1432. A click of the UNDO button brings the BG screen, with the pre-eraser version
  1433. of your painting, back to the fore.  Another use is for buffering the contents
  1434. of the screen when something like a dialog box or a menu is written over it.
  1435. When a dialog box is erased, and you see whatever had been underneatg it
  1436. magically reappear, the graphics underneath are being pulled from the BG
  1437. screen.
  1438.  
  1439. Applications have the option not to use the BG screen.  Change a couple of
  1440. vectors and flags, and you can use the 8K BG screen for application RAM.
  1441. (This is very convenient, since the BG screen is directly above the normal 22K
  1442. of application RAM in the GEOS memory map.)  Of course, the application then
  1443. has to provide some way of redrawing blocks of the screen hidden by menus and
  1444. dialog boxes.  geoWrite is an example of this; when you bring up, and exit
  1445. from, a dialog box in geoWrite, there is briefly a blank rectangle on the
  1446. screen before the text is redrawn on the screen.
  1447.  
  1448. Under GEOS128 in 80 columns, the bitmap screen is now twice as large: 640x200
  1449. instead of 320x200.  The FG screen, here 16K, occupies VDC memory.  The memory
  1450. used for both the 40 column FG and 40 column BG screen is used for the 80
  1451. column BG screen.
  1452.  
  1453. GEOS128 was written for, and runs on, 128's with only the usual 16K of VDC
  1454. RAM.  And, it uses basically all 16K of this RAM.  However, if you have 64K of
  1455. VDC RAM (as is the case with 128D's, and with flat 128's that have been
  1456. upgraded), you've got an additional 48K of VDC RAM that the GEOS system
  1457. doesn't touch.  So, why not use some of this RAM as a 80 column BG screen?
  1458. Then, if you are writing an 80-column only application, you get an extra 16K,
  1459. the 40-column BG screen at $6000 and the 40-column FG screen at $a000, in main
  1460. memory which your application can use however it sees fit.
  1461.  
  1462.  
  1463. II. Support Routines
  1464.  
  1465. Only a small number of routines actually need to be written to implement this
  1466. scheme; moreover, these routines are realatively straightforward.  After all,
  1467. we are simply copying memory from one part of VDC RAM to another.  The VDC's
  1468. block copy feature of the VDC is very helpful in this endeavor.  (See Craig
  1469. Taylor's article from last issue, or most any 128 programming guide.)  The
  1470. file vdc-bg.sfx, associated with this issue of the Hacking Mag, is a
  1471. self-extracting archive with a number of geoProgrammer source files (in
  1472. geoWrite 2.1 format) and a small dippy demonstration program.  The file VDC-BG
  1473. contains the following routines:
  1474.  
  1475. InitVDC       -- make sure your VDC knows it has 64K RAM
  1476. VDCImpLine    -- Imprint horizontal line from FG screen to BG screen
  1477. VDCRecLine    -- Recover horizontal line from BG screen to FG screen
  1478. VDCImpRect    -- Imprint rectangle from FG screen to BG screen
  1479. VDCRecRect    -- Recover rectangle from BG screen to FG screen
  1480.  
  1481. Each Imprint routine actually uses most of the same code as the corresponding
  1482. Recover routine; all that differs is the offset to the "source" and
  1483. "destination" screens in VDC RAM.  (The offset for the FG screen is $0000, and
  1484. for the BG screen is $4000.)  The routines take the same arguments as the
  1485. non-VDC Imprint and Recover routines as documented in the Hitchhiker's Guide.
  1486. (You will note, however, that for whatever reason the standard GEOS
  1487. ImprintLine and RecoverLine routines were only implemented for Apple GEOS.)
  1488. Briefly, these are:
  1489.  
  1490. Routine:     InitVDC
  1491.  
  1492. Pass:        Nothing
  1493.  
  1494. Return:      Nothing
  1495.  
  1496. Destroys:    a,x
  1497.  
  1498. Note:        This routine should be called at the very beginning of your
  1499.              program before you do any writing to the FG screen or the VDC.
  1500.  
  1501. ------------------------------------------------------------------------------
  1502.  
  1503.  
  1504. Routine:     VDCImpLine
  1505.              VDCRecLine
  1506.  
  1507. Pass:        r3   -- left edge of line to imprint/recover (word)
  1508.              r4   -- right edge of line to imprint/recover (word)
  1509.              r11L -- y coordinate of line to imprint/recover (byte)
  1510.  
  1511. Return:      r3, r4 -- processed through NormalizeX
  1512.  
  1513. Destroys:    a,x,y,r5-r8,r11
  1514.  
  1515. -------------------------------------------------------------------------------
  1516.  
  1517. Routine:     VDCImpRect
  1518.              VDCRecRect
  1519.  
  1520. Pass:        r3   -- x-coordinate of upper-left corner (word)
  1521.              r2L  -- y-coordinate of upper-left corner (byte)
  1522.              r4   -- x-coordinate of lower-right corner (word)
  1523.              r2H  -- y-coordinate of lower-right corner (byte)
  1524.  
  1525. Return:      r3,r4 -- processed through NormalizeX
  1526.  
  1527. Destroys:    a,x,y,r5-r8,r10L,r11
  1528.  
  1529. ------------------------------------------------------------------------------
  1530.  
  1531.  
  1532. To discuss the imprint and recover line routines, consider the ASCII diagram
  1533. of a portion of a line on the VDC screen.  A x indicates a pixel that is in
  1534. the line to be copied.  The I's indicate byte boundaries; the pixel below each
  1535. I is the msb of the corresponding byte in the VDC bitmap.  (Bytes increase
  1536. horizontally across the screen; there is no card structure found in the 80
  1537. column bitmap screen.)
  1538.  
  1539.            I       I       I       I
  1540.            ....xxxxxxxxxxxxxxxxxxxxxxxxx...
  1541.                 ^  \______________/  ^
  1542.              left          I         right
  1543.           residual     full bytes    residual
  1544.  
  1545. The line moving routine needs to figure the location in VDC RAM of the
  1546. leftmost full byte, the number of full bytes, and the location of the two
  1547. residual bytes; additionally, it builds a bit mask for the residual bytes,
  1548. with bits set corresponding to pixels to be copied.  This mask is used to
  1549. create the proper combination of data from the source and destination screens
  1550. in the two residual bytes.
  1551.  
  1552. Once it knows all this, all the line routines do is (1) submit a VDC block
  1553. copy to copy the full bytes, (2) read the left residual byte from the source,
  1554. mask out the appropriate pixels, and OR it with the appropriate pixels from
  1555. the destination, and write that one byte (3) repeat (2) for the right residual
  1556. byte.
  1557.  
  1558. The rectangle routines simply call the line copy routines repeatedly,
  1559. (r2H)-(r2L)+1 times.  (Note that while this is the most efficient way to do it
  1560. from a coding time point of view <grin>, really the rectangle routines only
  1561. need calculate the residual bit masks and the locations once.  Thereafter,
  1562. locations can be updated by adding 80 (the length of a VDC line) for each new
  1563. line.  The changes to the code to implement this are not difficult, and it
  1564. isn't clear why I didn't make them....)
  1565.  
  1566.  
  1567. III. Use of the Routines
  1568.  
  1569. In a word, you use these routines whenever you would have used the normal GEOS
  1570. imprint/recover routines.  There are a few other consierations, though.
  1571.  
  1572. First of all, you need to set the flag dispBufferOn to ST_WR_FORE.  The GEOS
  1573. system graphic routines think that the BG screen is in main memory, and thus
  1574. will not correctly use your new VDC BG screen.  This means, unfortunately,
  1575. that you can't just blithely go drawing graphics, assuming that they'll be
  1576. buffered for recall when needed.  However, it is not too much trouble to make
  1577. a call to VDCImpRect either right after you've made some graphic change, or
  1578. right before something potentially hazardous will happen (e.g. a call to
  1579. DoDlgBox).  For instance, you might have all of your main menus be Dynamic
  1580. Submenus which call VDCImpRect before opening the submenu.
  1581.  
  1582. Second, you should load recoverVector with VDCRecRect.  Since VDCRecRect takes
  1583. the same parameters as RecoverRectangle, it can substitute directly for it.
  1584. Once you set this vector, all menus and dialog boxes erased from the screen
  1585. automatically restore the destroyed region from your VDC BG screen.
  1586.  
  1587. Both of these are demonstrated in the test program included in vdc-bg.sfx.
  1588.  
  1589.  
  1590. IV. Another 32K
  1591.  
  1592. The alert reader will have noticed that the VDC BG screen only takes as much
  1593. memory as the VDC FG screen, i.e. 16K.  Thus, even with this scheme, there is
  1594. still another 32K of free memory in VDC RAM.  Quadruple buffering, anyone?
  1595.  
  1596. A more tantalizing prospect would be to implement a 640x400 interlaced screen
  1597. for GEOS128.  This presents a number of problems, however.  First, there is
  1598. that terrible flicker.  But, this can be made reasonable through the use of
  1599. polarizing filters (in layman's terms, "sunglasses") and appropriate color
  1600. choices.  More seriously, the GEOS kernal graphic routines all take byte
  1601. argum`>:s for Y coordinates.  So, all 400 vertical pixels cannot be addressed
  1602. with those routines.  Thus, sombody implementing a GEOS interlaced screen is
  1603. faced with re-writing all of the graphics routines.  (Something to do with the
  1604. 8K you've freed up at $a000, I suppose.)  Since each 640x400 graphic screen
  1605. would require 32K of memory for the bitmap, you could still have a VDC
  1606. Background screen.
  1607.  
  1608. [ Note: The code discussed within this article is available via anonymous 
  1609. FTP at tybalt.caltech.edu under the directory pub/rknop/hacking.mag as 
  1610. vdc-bg.sfx. This will dissolve into the GEOWRITE source files.]
  1611.  
  1612. ============================================================================
  1613.  
  1614. GeoPaint File Format
  1615. --------------------
  1616. by Bruce Vrieling (bvrieling@undergrad.math.waterloo.edu)
  1617.  
  1618. GeoPaint is an excellent graphics program written for the GEOS environment. Its
  1619. disk access is relatively quick, compared it to what a comparable program would
  1620. do on a non-GEOS equipped C64. Part of this accomplishment can be attributed to
  1621. the diskTurbo that is an integral part of GEOS. However, the special GeoPaint
  1622. file-saving scheme deserves some of the credit.
  1623.  
  1624.  
  1625. VLIR
  1626. ----
  1627.  
  1628. GeoPaint files are always stored in Variable Length Indexed Recording files. 
  1629. VLIR files offer advantages not available without GEOS. Generally speaking, VLIR
  1630. is the ultimate in RELATIVE files.
  1631.  
  1632. The format of a VLIR file is not that difficult to figure out. While in a 
  1633. regular C64 file, the two bytes directly following the FILETYPE byte in the 
  1634. directory would point to the data file following, VLIR files use these two bytes
  1635. to point to a VLIR HEADER BLOCK (don't confuse the VLIR HEADER block with the
  1636. INFO block). The first two bytes of this block are $00/FF, as the header block 
  1637. is a MAXIMUM of one block long. (This is why when you VALIDATE a GEOS disk from
  1638. C64 mode, GeoPaint pictures are lost. Only the header block is recognised as 
  1639. being part of the file. The rest of the picture gets deallocated in the BAM). 
  1640. The remaining 254 bytes in the block are divided into 127 2-byte pointers to 
  1641. tracks/sectors on the disk. These pointers point to the individual records of 
  1642. the VLIR file, which may be ANY number of blocks long. The VLIR track/sector 
  1643. pointers in the VLIR header block only point to the FIRST block of the chain. 
  1644. From then on, the sectors chain themselves together using the normal format ie.
  1645. the first two bytes of each block point to the following block.
  1646.  
  1647. A sample GeoPaint VLIR header might look like this:
  1648.  
  1649. 0000:00 FF 03 11 03 05 03 01 ........
  1650. 0008:04 03 00 FF 00 FF 00 FF ........
  1651. 0010:04 07 00 00 00 00 00 00 ........
  1652.  etc....
  1653.  
  1654. The first two bytes, $00/FF, tell the drive that this is the last (and only) 
  1655. block in this VLIR HEADER SECTION (will never be more than 1 block, as was 
  1656. mentioned earlier). The next pair of bytes, $03/11, points to the first VLIR 
  1657. record. The next two, $03/05, point to the second record.
  1658.  
  1659. You will notice that 5th record contains the values $00/FF. This means that for
  1660. this record, there is no picture data. We will get into exactly what the data 
  1661. held in the records mean in a minute. The $00/FF entries indicate an empty 
  1662. record. Finally, the 9th entry, $00/00 indicates the end of the GeoPaint file.
  1663. There is no more data beyond this point.
  1664.  
  1665. One note should be made. GeoPaint is not always consistent in its handling of 
  1666. the data in a header block. Sometimes, it will show quite a few $00/FF 
  1667. combinations before finally terminating with a $00/00. When reading the file, 
  1668. I always read the entire header, as I don't trust the end of file method 
  1669. mentioned above. Just remember that any track/sector link that does not contain
  1670. $00/FF or $00/00 is a valid record, with picture data.
  1671.  
  1672.  
  1673. Layout on Screen
  1674. ----------------
  1675.  
  1676. GEOS orients the data in a GeoPaint file slightly differently than in a 
  1677. PhotoScrap or an Icon. A photoscrap stores the bytes corrosponding to a screen
  1678. which looks like this:
  1679.  
  1680. 001 002 003 004 005 ....0012
  1681. 013 014 015 016 017 ....0024
  1682.  
  1683. Consecutive bytes are placed BESIDE each other. However, if you are at all
  1684. familiar with the layout of a C64 hi-res screen, you will know this is very 
  1685. different from the layout that the VIC chip sees data. GeoPaint uses a format 
  1686. identical to the VIC chip layout on screen.
  1687.  
  1688. GeoPaint pictures are stored in the following format:
  1689.  
  1690. 001 009 017 025 033 .....  313
  1691. 002 010 018 026 034 .....  314
  1692. 003 011 019 027 035 .....  315
  1693. 004 012 020 028 036 .....  316
  1694. 005 013 021 029 037 .....  317
  1695. 006 014 022 030 038 .....  318
  1696. 007 015 023 031 039 .....  319
  1697. 008 016 024 032 040 .....  320
  1698.  
  1699. 321 329 .....
  1700. 322 330 .....
  1701. 323 331 .....
  1702. 324 332 .....
  1703. 325 333 .....
  1704. 326 334 .....
  1705. 327 335 .....
  1706. 328 336 .....
  1707.  
  1708. As you can see, this is very different from the PhotoScrap format. Consecutive
  1709. bytes are NOT stored on the screen beside each other. Rather, they are stored
  1710. underneath each other into groups of 8 bytes. This makes moving the data from 
  1711. the disk onto the screen that much faster, as the decompacted bytes can just be
  1712. stored on the screen after each other. Of course, this makes porting GEOS pics
  1713. to the 128's VDC that much more difficult, as the VDC conforms to the 
  1714. PhotoScrap format.
  1715.  
  1716.  
  1717. Compression Method
  1718. ------------------
  1719.  
  1720. GEOS uses an excellent compression method to store files on disk. You may have
  1721. noticed that nearly empty pictures on disk consume very little disk space. This
  1722. can be credited to GeoPaint's smart compression techniques.
  1723.  
  1724. Basically, the format of the compression has one COMMAND byte followed by one 
  1725. or more DATA bytes. The COMMAND byte tells GEOS what to do with following DATA 
  1726. bytes. There are 4 commands for compression:
  1727.  
  1728. 1) If the COMMAND byte is less than 64, this indicates that there are 'COMMAND'
  1729.    many DATA bytes following that are to be taken as individual bytes. This is
  1730.    the least effective method of compression, as no compression takes place.
  1731.  
  1732. 2) If the COMMAND byte ranges from 65 to 127, then this is a special type of 
  1733.    compression. First of all, the next 8 bytes in the file are read in as DATA.
  1734.    This DATA is used to make an 8*8 'stamp'. Secondly, the amount of times to 
  1735.    'stamp' this 8*8 square is calculated (COMMAND AND 63). Then, the stamping 
  1736.    is done. 'Stamping' sounds more difficult that it really is. What it boils
  1737.    down to, is repeating the 8 byte DATA stamp 'COMMAND AND 63'
  1738.    times.
  1739.  
  1740. 3) If the COMMAND byte is 129 or greater, then the following DATA byte is
  1741.    repeated 'COMMAND AND 127' times. This is different from #1, as only 1 DATA
  1742.    byte is called in, and simply repeated. #1 called in 'COMMAND' many DATA 
  1743.    bytes.
  1744.  
  1745. 4) If the COMMAND byte is ZERO, we have reached the end of the VLIR record for
  1746.    the GeoPaint picture.
  1747.  
  1748. It should be noted that the COMMAND byte will NEVER be 64 or 128. If it is, 
  1749. there has been an error.
  1750.  
  1751.  
  1752. Format of Data After Decompacting
  1753. ---------------------------------
  1754.  
  1755. After the data has been decompacted, it remains to be placed on the screen. Each
  1756. VLIR record holds 16 scanlines of data, or 2 character lines (different ways of
  1757. looking at the same thing).
  1758.  
  1759. The format of the data is as follows:
  1760.  
  1761.      First, there is 640 bytes of picture data, comprising the first character
  1762.      line (8 scanlines). Remember, GeoPaint pictures are 640 pixels across. 640
  1763.      pixels works out to 80 bytes. A character line is 8 pixels deep, so 80*8 
  1764.      comes to 640 bytes.
  1765.  
  1766.      These bytes are followed by the 640 bytes for the second chacacter line 
  1767.      (next 8 scanlines). This is followed by 8 garbage bytes that accidentaly 
  1768.      worked themselves into the original GeoPaint design. They should be set to
  1769.      zero.
  1770.  
  1771.      Finally, two sets of 80 bytes of colour data follow. The first set 
  1772.      comprises the colour for the first line, the second 80 bytes for the second
  1773.      line. To wrap things up, the VLIR record is terminated by a zero byte.
  1774.  
  1775.      The next VLIR record will hold the data for the NEXT 16 scanlines, and so
  1776.      on.
  1777.  
  1778.  
  1779. Conclusion
  1780. ----------
  1781.  
  1782. That about wraps up this discussion on GeoPaint format for files. We've 
  1783. discussed the format of VLIR files on disk, layout of picture data on screen, 
  1784. compression methods used in GeoPaint files, and the format of the data once 
  1785. decompacted. I hope this information will come in handy for someone.
  1786.  
  1787. ==============================================================================
  1788. Rasters - What They Are and How to Use Them
  1789. by Bruce Vrieling - (bvrieling@undergrad.math.waterloo.edu)
  1790.  
  1791. Anyone who has fiddled around with interrupts on the Commodore 64 has 
  1792. undoubtedly heard at one time or another of the concept of rasters being 
  1793. mentioned. Rasters are the 'ultimate' achievement of interrupt programming, or
  1794. so they say. What is a raster? And how does one go about writing a program to 
  1795. use them?
  1796.  
  1797. Overview of what Interrupts are all about
  1798. -----------------------------------------
  1799.  
  1800. A raster is sort form for the concept of a 'raster interrupt'. Before
  1801. going into rasters, perhaps a brief review of interrupts is in order.
  1802.  
  1803. Interrupts are events generated by the CIA timer in the C64 to perform certain 
  1804. tasks. 60 times a second, the CIA chip signals an interrupt is due to be 
  1805. processed (ie. the interrupt timer timed out). This causes the 6510 CPU to stop
  1806. executing the current program, save the registers on the stack, and begin to 
  1807. execute the interrupt code. Some of the things which get done during an 
  1808. interrupt include the keyboard scan, and updating TI (the software clock). When
  1809. the interrupt code is finished, an RTI instruction is executed, which brings 
  1810. the interrupt's execution to a halt. The registers are retrieved from the stack,
  1811. and the current program in memory continues to execute once again. It will 
  1812. continue to do so until the next interrupt occurs, about 1/60 of a second later.
  1813. The above is what happens in a normal C64 (the C128 follows the same idea, but 
  1814. more events occur during a C128 interrupt). [Ed. Note: In addition, the C=128
  1815. generates its interrupts via a screen raster instead of the CIA chip.]
  1816.  
  1817. However, you can change the normal course of events, and cause some code of your
  1818. design to be added to the normal list of events which occur every interrupt. 
  1819. Some of the simple favourites include flashing the border 60 times per second.
  1820. (Note that we have not begun the topic of rasters yet; this has nothing to do
  1821. with rasters. That discussion begins at the next heading.)
  1822.  
  1823. How do you change the interrupt's normal course of action? It's rather simple.
  1824. The C64 contains an interrupt VECTOR at locations 788/9 which is 'jumped 
  1825. through' before the Kernal Rom gets a chance to execute its code. If you change
  1826. this vector to point to YOUR code, and make the end of your code point to the 
  1827. normal Kernal location (where the interrupt normally would have jumped to, 
  1828. $EA31), and you are careful not to step on anything, your code will be executed
  1829. 60 times per second.
  1830.  
  1831. An example is in order:
  1832.  
  1833. ; flasher
  1834. ;
  1835. ; this program causes the border to flash 60 times per second
  1836. ;
  1837. setup = *
  1838.  
  1839. sei                           ; disable interrupts
  1840. lda #<intcode                 ; get low byte of target routine
  1841. sta 788                       ; put into interrupt vector
  1842. lda #>intcode                 ; do the same with the high byte
  1843. sta 789
  1844. cli                           ; re-enable interrupts
  1845. rts                           ; return to caller
  1846.  
  1847. intcode = *
  1848.  
  1849. inc $d020                     ; change border colour
  1850. jmp $ea31                     ; exit back to rom
  1851.  
  1852.  
  1853. The above is an example of a very simple interrupt routine. If you were to 
  1854. assemble it with an assembler, and SYS to the SETUP routine, you would see your
  1855. border flash 60 times per second.
  1856.  
  1857. You will notice the SEI and CLI machine language instructions used above. They
  1858. are very important. We don't want an interrupt occurring in between the STA 788
  1859. and the STA 789 instructions.
  1860.  
  1861. Think what would happen if one did: 788 would have been modified, but 789 would
  1862. still be pointing to the high byte of the Kernal address. Result: the interrupt
  1863. would have jumped to heaven knows where. You can be virtually guaranteed that 
  1864. it would NOT be pointing to a valid piece of interrupt code. Your machine would
  1865. crash. The SEI instruction turns interrupts OFF, so that there is no danger of 
  1866. an interrupt occurring during execution of the following routine. The CLI turns
  1867. them back on. If you forget to turn them back on, and accidentally leave them 
  1868. off, your keyboard will freeze when you return to basic, and your machine will
  1869. seem to lock up.
  1870.  
  1871. The above was a very simple example. There are many useful things which can also
  1872. be done on an interrupt. I have seen code which played music in the background
  1873. of a running Basic program (it played the popular .MUS files). GEOS uses 
  1874. interrupts extensively to control the pointing of the mouse, and to trigger 
  1875. events. Interrupts are powerful beasts, and the following concept concerning 
  1876. raster interrupts specifically is a particularly useful animal for some people.
  1877.  
  1878.  
  1879. The Raster
  1880. ----------
  1881.  
  1882. A raster is a loosely used term. It refers to an interrupt that is triggered 
  1883. when the ray gun on the back of your monitor draws a certain line on the video
  1884. screen. There are many different sources which can cause an interrupt. You are 
  1885. not limited to what the CIA chip can do. Rasters depend on interrupts 
  1886. specifically generated by the VIDEO chip. You could make this interrupt change
  1887. the border colour of the screen below a certain screen line. When the screen 
  1888. line you specified gets redrawn, the interrupt goes off. Your code then quickly
  1889. changes some memory locations to create a different video mode or effect. You 
  1890. could cause the bottom half of the screen to gets it's character definitions 
  1891. from another, different character set. Or, you could make the top 3/4 of your 
  1892. screen exist in hi-res multi-colour graphics, and keep the bottom 1/4 of the 
  1893. screen in text mode.
  1894.  
  1895. Some facts about the video screen: it gets redrawn exactly 60 times per second.
  1896. It contains 200 scan lines on the normal 25*40 display, numbered 50 to 250 or 
  1897. thereabouts (note that there are more visible scan lines though: the top and 
  1898. bottom borders, for example). The actual re-drawing of the screen is 
  1899. synchronized to the electrical power coming into your house, 60 Hz. That's why
  1900. some programs behave differently when run on European machines. The power is 
  1901. delivered at 50 Hz over there.
  1902.  
  1903. Why do we have to worry about a video interrupt? If the screen gets redrawn 60
  1904. times per second, and regular interrupts also occur at 60 times per second, why
  1905. not simply put some code into the regular interrupt to do what we want with the
  1906. screen? Because the two types of interrupts are not in sync. Neither one of them
  1907. occurs EXACTLY 60 times per second, and the differences are enough to make it 
  1908. next to impossible to get coordinated activity of any kind happening on the 
  1909. screen. When we use the video interrupt, we KNOW we are at a certain line on the
  1910. screen, as being on that line is what caused the interrupt to happen in the
  1911. first place.
  1912.  
  1913. So, let's summarize. We know that regular interrupts occur 60 times per second.
  1914. We also know that the video screen gets re-drawn 60 times per second, and that
  1915. we can cause an interrupt to be generated when a certain line gets drawn on the
  1916. screen. One slight drawback to all of this is that BOTH types of interrupts
  1917. (regular and raster driven) travel through the SAME vector (ie. about 120 
  1918. interrupts per second, 60 of one, and 60 of the other). Your code will have to
  1919. check and see what the source of the interrupt was, and act accordingly. Or will
  1920. it?
  1921.  
  1922. The system needs an interrupt to occur 60 times per second to do housekeeping,
  1923. and uses the CIA clock to generate the interrupts. We want to interrupt every 
  1924. time a certain scan line is reached on the monitor, which will also just happen
  1925. to occur at 60 times per second. We also have to make sure that they don't 
  1926. interfere with each other. The regular interrupts should be sent to their Rom
  1927. destination, while our video interrupts should go to our code, and no where 
  1928. else.
  1929.  
  1930. If both are occurring at 60 times per second, why not do the job of the system
  1931. Rom, and our video code on the SAME interrupt? We know that the CIA chip is not
  1932. good for this; it is out of sync with the video image. Why not turn OFF the CIA
  1933. interrupt, enable the raster/video interrupt, and do both jobs on one interrupt?
  1934. Then we would have an interrupt signal that occurs 60 times per second, and is
  1935. in perfect sync with the video image.
  1936.  
  1937. That's exactly what we're going to do.
  1938.  
  1939. Astute reads will notice a slight flaw in the above logic. For simplification 
  1940. purposes, I didn't get into the fact that you will need TWO raster interrupts 
  1941. PER SCREEN to accomplish anything useful. Why two? Because any change to the 
  1942. video mode you put into effect 3/4 of the way down the screen will have to be 
  1943. undone at the TOP of the next screen update. If you decide to make the top 3/4 
  1944. of the screen a hi-res image, and the bottom 1/4 text, you need one interrupt 
  1945. 3/4 of the way down the screen to change from hi-res to text, but you need a 
  1946. SECOND one at the top of the screen to change back to hi-res from text.
  1947.  
  1948. So, we will now have 120 interrupts going off every second to accomplish our 
  1949. video desires, with 60 of them working a double shift, making sure the system 
  1950. interrupt code gets executed also. Remember that we are working with a specific
  1951. example. There is no reason why you couldn't split the screen into N different
  1952. video modes, and have (N+1)*60 interrupts going off per second. As long as you 
  1953. keep your code short (so your interrupts don't take too long, and have another 
  1954. interrupt occur before the current one is done - messy), it will work 
  1955. beautifully.
  1956.  
  1957. So far, this is all talk. Let's write a few short code segments to accomplish 
  1958. some of the feats we've just discussed.
  1959.  
  1960. The first we'll do is a re-hash of the one presented above. It flashes the 
  1961. border again. It does not do any mid-screen changes of video modes or anything 
  1962. fancy like that, so only 1 interrupt per screen is required (ie. 60 per second,
  1963. not 120 etc.). This program simply shows the same idea, but this time using 
  1964. video interrupts as the source rather than the CIA. You probably won't
  1965. notice a difference during execution.
  1966.  
  1967. ----------------------------------------------------------------------------
  1968. ; flasher - part II
  1969. ;
  1970. ; this program causes the border to flash 60 times per second
  1971. ; the source of the interrupts is the video chip
  1972. ;
  1973. setup = *
  1974.  
  1975. sei                           ; disable interrupts
  1976.  
  1977. lda #$7f                      ; turn off the cia interrupts
  1978. sta $dc0d
  1979.  
  1980. lda $d01a                     ; enable raster irq
  1981. ora #$01
  1982. sta $d01a
  1983.  
  1984. lda $d011                     ; clear high bit of raster line
  1985. and #$7f
  1986. sta $d011
  1987.  
  1988. lda #100                      ; line number to go off at
  1989. sta $d012                     ; low byte of raster line
  1990.  
  1991. lda #>intcode                 ; get low byte of target routine
  1992. sta 788                       ; put into interrupt vector
  1993. lda #<intcode                 ; do the same with the high byte
  1994. sta 789
  1995. cli                           ; re-enable interrupts
  1996. rts                           ; return to caller
  1997.  
  1998.  
  1999. intcode = *
  2000.  
  2001. inc $d020                     ; change border colour
  2002.  
  2003. lda $d019                     ; clear source of interrupts
  2004. sta $d019
  2005.  
  2006. lda #100                      ; reset line number to go off at
  2007. sta $d012
  2008.  
  2009. jmp $ea31                     ; exit back to rom
  2010. --------------------------------------------------------------------------
  2011.  
  2012. As you can tell, there's a wee bit more to this code than there was in the 
  2013. original. Execute it, and you'll notice that it looks pretty much the same as 
  2014. the results from the first program. But there's a difference: the interrupts 
  2015. are now being generated from the video chip, not the CIA. For this program, it 
  2016. didn't make much difference. However, for a more complicated program, it makes
  2017. a world of difference.
  2018.  
  2019. I'd better explain some of the code used above:
  2020.  
  2021.      lda #$7f
  2022.      sta $dc0d
  2023.  
  2024.      - This piece disables any interrupts caused by the CIA chip.
  2025.  
  2026.      lda $d01a
  2027.      ora #$01
  2028.      sta $d01a
  2029.  
  2030.      - Location $d01a controls which sources may cause an interrupt
  2031.        (other than the normal CIA). There are 4 different possible
  2032.        sources: rasters, sprite to sprite collision, sprite to
  2033.        background collision, and the light pen. Bit #0 is the raster
  2034.        bit, and this piece of code activates it.
  2035.  
  2036.      lda $d011
  2037.      and #$7f
  2038.      sta $d011
  2039.  
  2040.      - This code clears bit #7 of location $d011. This location is used
  2041.        for many different things. Bit #7 represents the highest bit of
  2042.        the raster line (see segment below for more on the raster line
  2043.        #). More than 256 raster line numbers are possible (some are off
  2044.        screen, and some represent the upper and lower border areas).
  2045.        This bit is the 9th bit. I set it to zero because all my code
  2046.        affects rasters only on the normal 25*40 line display, well
  2047.        within the 0-255 range. This decision was an arbitrary choice on
  2048.        my part, to make the code simpler.
  2049.  
  2050.      lda #100
  2051.      sta $d012
  2052.  
  2053.      - Location $d012 is the lower 8 bits of the raster line on which
  2054.        the interrupt is to be generated. The number 100 was another
  2055.        arbitrary choice. For changing border colours, the actual line
  2056.        number was not important. Later on, in the next example, it will
  2057.        become important.
  2058.  
  2059.      lda #>intcode
  2060.      ...
  2061.      rts
  2062.  
  2063.      - Re-vectors the interrupt code to the new code.
  2064.  
  2065.      inc $d020
  2066.  
  2067.      - Changes the border colour.
  2068.  
  2069.      lda $d019
  2070.      sta $d019
  2071.  
  2072.      - These lines clear the bit in the interrupt register which tells the
  2073.        source of the interrupt (in preperation for the next).
  2074.  
  2075.      lda #100
  2076.      sta $d012
  2077.  
  2078.      - This line resets the raster line to go off at line number 100
  2079.        again (same as above). It should be reset, so the next interrupt
  2080.        will know what line to occur on.
  2081.  
  2082.      jmp $ea31
  2083.  
  2084.      - Exit back to the Kernal Rom.
  2085.  
  2086.  
  2087. A Useful Example
  2088. ----------------
  2089.  
  2090. The following is an example of a more sophisticated piece of raster code. It 
  2091. makes the top half of the screen border white, and the bottom half black.
  2092.  
  2093. ---------------------------------------------------------------------------
  2094. setup = *
  2095.  
  2096. ; some equates
  2097.  
  2098. COLOUR1 = 0
  2099. COLOUR2 = 1
  2100. LINE1 = 20
  2101. LINE2 = 150
  2102.  
  2103. ; code starts
  2104.  
  2105. setup = *
  2106.  
  2107. sei                           ; disable interrupts
  2108.  
  2109. lda #$7f                      ; turn off the cia interrupts
  2110. sta $dc0d
  2111.  
  2112. lda $d01a                     ; enable raster irq
  2113. ora #$01
  2114. sta $d01a
  2115.  
  2116. lda $d011                     ; clear high bit of raster line
  2117. and #$7f
  2118. sta $d011
  2119.  
  2120. lda #LINE1                    ; line number to go off at
  2121. sta $d012                     ; low byte of raster line
  2122.  
  2123. lda #>intcode                 ; get low byte of target routine
  2124. sta 788                       ; put into interrupt vector
  2125. lda #<intcode                 ; do the same with the high byte
  2126. sta 789
  2127.  
  2128. cli                           ; re-enable interrupts
  2129. rts                           ; return to caller
  2130.  
  2131. intcode = *
  2132.  
  2133. lda modeflag                  ; determine whether to do top or
  2134.                               ; bottom of screen
  2135. beq mode1
  2136. jmp mode2
  2137.  
  2138. mode1 = *
  2139.  
  2140. lda #$01                      ; invert modeflag
  2141. sta modeflag
  2142.  
  2143. lda #COLOUR1                  ; set our colour
  2144. sta $d020
  2145.  
  2146. lda #LINE1                    ; setup line for NEXT interrupt
  2147. sta $d012                     ; (which will activate MODE2)
  2148.  
  2149. lda $d019
  2150. sta $d019
  2151.  
  2152. jmp $ea31                     ; MODE1 exits to Rom
  2153.  
  2154. mode2 = *
  2155.  
  2156. lda #$00                      ; invert modeflag
  2157. sta modeflag
  2158.  
  2159. lda #COLOUR2                  ; set our colour
  2160. sta $d020
  2161.  
  2162. lda #LINE2                    ; setup line for NEXT interrupt
  2163. sta $d012                     ; (which will activate MODE1)
  2164.  
  2165. lda $d019
  2166. sta $d019
  2167.  
  2168. pla                           ; we exit interrupt entirely.
  2169. tay                           ; since happening 120 times per
  2170. pla                           ; second, only 60 need to go to
  2171. tax                           ; hardware Rom. The other 60 simply
  2172. pla                           ; end
  2173. rti
  2174.  
  2175. modeflag .byte 0
  2176.  
  2177. ----------------------------------------------------------------------------
  2178.  
  2179. The above code, when executed, will result in the top half of your border being
  2180. white, and the bottom black. You may wish to fiddle with the equates (COLOUR1,
  2181. COLOUR2, LINE1, and LINE2) to get different effects.
  2182.  
  2183. I see some confused faces concerning why the above exit the interrupts the way 
  2184. they do. Remember, since we want a split screen effect, we have to have one 
  2185. interrupt occur at the TOP of the screen, to turn on the WHITE effect, and one 
  2186. midway down to turn on the BLACK effect. Two interrupts times 60 means 120
  2187. interrupts will be executed per second. The Rom only needs 60 per second to 
  2188. service the keyboard and its other stuff. So, we send 60 to the Rom (the 
  2189. interrupts which go through MODE1) by JMPing to $EA31, and the other 60 we 
  2190. trash. The PLA... RTI business is the proper way to bring an interrupt to an end
  2191. without going through the Rom. The RTI will ReTurn from Interrupt, and cause the
  2192. regular program to continue to execute.
  2193.  
  2194. That brings to an end this discussion on rasters. I hope the above examples 
  2195. have proved to be a valuable learning tool for you. With luck, they will 
  2196. motivate you to continue to experiment with rasters, and come up with some neat
  2197. effects.
  2198.  
  2199. If you have any questions, be sure to ask me about them.
  2200.  
  2201. ==============================================================================
  2202. BURSTING YOUR 128: THE FASTLOAD BURST COMMAND
  2203. by Craig Bruce <f2rx@jupiter.sun.csd.unb.ca>
  2204.  
  2205. 1. INTRODUCTION
  2206.  
  2207. This article discusses the well-unknown Fastload command of the 1571 and 1581
  2208. disk drive Burst Command Instruction Set.  If you look in the back of your '71
  2209. (or '81 I presume) disk drive manual, you will find that the information given
  2210. about the Fastload utility is not exactly abundant.
  2211.  
  2212. The Fastload command was intended to load program files into memory for
  2213. execution, but it can be used just as well for reading through sequential
  2214. files that would be much too large to load into a single bank of internal
  2215. memory.
  2216.  
  2217. To make use of the Fastload burst command, I implement a word counting utility
  2218. that will count the number of lines, words, and characters in a text file on a
  2219. 1571 or 1581 disk drive.  The advantage of using the Fastload command over
  2220. regular sequential file accessing through the kernel and DOS is that the
  2221. Fastload operates about 3.5 times faster on both drives.
  2222.  
  2223. 2. WORD COUNTING UTILITY
  2224.  
  2225. To use the word counting program, LOAD and RUN it like a regular BASIC
  2226. program.  It will ask you for the name of a file.  Enter the name if it is on
  2227. device number 8, or put a one character prefix and a ":" if it is on another
  2228. device.  A "b" means device 9, "c" device 10, etc.  The following are examples
  2229. of valid names:
  2230.  
  2231. . filename          "filename" on device 8
  2232. . b:filename        "filename" on device 9
  2233. . a:filename        "filename" on device 8
  2234.  
  2235. The file must be on either a 1571 or 1581 disk drive; the program will not
  2236. work with non-burst devices.  The program will work with either PRG or SEQ
  2237. files, since the Fastload command can be told not to worry about the file
  2238. type.
  2239.  
  2240. I use the same definition of a word as the Unix "wc" command uses: a sequence
  2241. of characters delimited by whitespace, where whitespace is defined to be
  2242. SPACE, TAB, and NEWLINE (Carriage Return) characters.  To get the line count,
  2243. I simply count the number of NEWLINEs.  If the last line of the file does not
  2244. end with a NEWLINE character, then the count will be one line short.  This is
  2245. the same as the Unix wc command too.  A proper text file should have its last
  2246. line end with a NEWLINE character.
  2247.  
  2248. On my JiffyDOS-ified 1571 and 1581, I am able to achieve a word counting speed
  2249. of 5,400 chars/sec and 6,670 chars/sec, respectively.  I am not sure how much
  2250. of a difference JiffyDOS makes, but I am not willing to rip out the ROMs to
  2251. check.  I tested using a 318K file.
  2252.  
  2253. 3. BURST READ LIBRARY
  2254.  
  2255. This section presents the burst reading library that you can incorporate into
  2256. your own programs and describes how the burst commands work.  The library has
  2257. three calls:
  2258.  
  2259. . burstOpen  ( .A=Device, .X=NameLen, burstBuf=Filename ) : <first block>
  2260. . burstRead  () : burstBuf, burstStatus, burstBufCount
  2261. . burstClose ()
  2262.  
  2263. I define three common storage variables for using this package: "burstBuf",
  2264. "burstStatus", and "burstBufCount".  "burstBuf" is a 256 byte area where the
  2265. data read in from the disk drive is stored before processing, and is located
  2266. at $0B00.  "burstStatus" is a zero-page location that keeps the status
  2267. returned from the burst command system.  This is needed by the user to detect
  2268. when the end of file has been encountered.  "burstBufCount" gives the number
  2269. of data bytes available in "burstBuf" after an open or read operation.  Its
  2270. value will be somewhere between 1 and 254.  A full sector contains 254 bytes
  2271. of data and two bytes of control information.
  2272.  
  2273. "burstStatus" and "burstBufCount" are defined to be at locations $FE and $FF,
  2274. respectively.  You are allowed to alter the values of the two variables and
  2275. the data buffer between calls, if you wish.  For reasons not completely
  2276. understood, interrupts must be disabled for the entire course of burst reading
  2277. a file.  I suspect this is because the IRQ service routine reads the interrupt
  2278. mask register of CIA#1, thus clearing the SerialDataReady flag that the burst
  2279. read routine waits for.  Anyway, the open routine does a SEI and the close
  2280. routine does a CLI, so you don't have to do this yourself.
  2281.  
  2282. If an error occurs during the exection of one of these routines, it will
  2283. return with the carry flag set and with the error code in the .A register
  2284. (same as the kernel (yes, I know that Commodore likes to call it the
  2285. "kernAl")).  Error codes 0 to 9 correspond to the standard kernel codes, error
  2286. code 10 means that the device is not a burst device, and error codes 16 to 31
  2287. correspond to the burst controller status codes 0-15.  If no error occurs, the
  2288. routines return with the carry flag clear, of course.
  2289.  
  2290. Only one file may be open at a time for Fastloading, since Fastload takes over
  2291. the disk drive and the entire serial bus.  Even regular files cannot be
  2292. accessed while a fastload is in progress.  Thus, Fastload is not suitable for
  2293. all file processing applications, but it works very well for reading a file
  2294. into memory (like for a text editor) and for summarization operations (like
  2295. word counting).  The burst library requires that the kernel and I/O space be
  2296. in context when it is called.
  2297.  
  2298. 3.1. BURST OPEN
  2299.  
  2300. The way that a burst command is given is to give a magical incantation over
  2301. the command channel to the disk drive.  You can either use the low-level
  2302. serial bus calls (LISTN, SECND, CIOUT, and UNLSN) or use the OPEN and CHROUT
  2303. calls.  I used the low level calls for a little extra zip.
  2304.  
  2305. The burst command format for Fastload is given in the back of your drive
  2306. manual:
  2307.  
  2308. .  BYTE \ bit: 7     6     5     4     3     2     1     0  | Value
  2309. . -------+--------+-----+-----+-----+-----+-----+-----+-----+-------
  2310. .   0    |     0  |  1  |  0  |  1  |  0  |  1  |  0  |  1  |  "U"
  2311. .   1    |     0  |  0  |  1  |  1  |  0  |  0  |  0  |  0  |  "0"
  2312. .   2    |     P  |  X  |  X  |  1  |  1  |  1  |  1  |  1  |  159
  2313. . 3 - ?? |                     <filename>                   |
  2314. . -------+--------------------------------------------------+-------
  2315.  
  2316. where "X" means "don't case" and "P" means "program".  If the P bit is '0'
  2317. then only program (PRG) files can be loaded, and if it is '1' then sequential
  2318. (SEQ) files can be loaded as well.  The package automatically sets this flag
  2319. for you.  Note that you don't have to do an Inquire Disk or Query Disk Format
  2320. in order to use this command like you have to do with the block reading and
  2321. writing commands.
  2322.  
  2323. If you want to try giving the incantation yourself, enter:
  2324.  
  2325. OPEN1,8,15,"U0"+CHR$(159)+"FILENAME"
  2326.  
  2327. (where "FILENAME" is the name of some file that exists on your disk) on your
  2328. 128 and your disk drive will spring to life and wait for you to read the file
  2329. data.  You can't read the data from BASIC, so to cancel the command:
  2330.  
  2331. CLOSE1
  2332.  
  2333. The "burstOpen" call of this package accepts the name of the file to be loaded
  2334. at the start of the "burstBuf" buffer, the length of the filename in the .X
  2335. register, and the device number to load the file from in the .A register.  The
  2336. burst command header and the filename are sent to the disk drive as described
  2337. above.
  2338.  
  2339. The open command also reads the first sector of the file, for two reasons.
  2340. First, the status byte returned for the first sector has special meaning.
  2341. Status code $02 means "file not found".  The package translates this into the
  2342. kernel error code.  Second, and most important, there is a bizarre feature
  2343. (read: "bug") in the Fastload command.  If the file to be read is only one
  2344. block long, then the number of bytes reported for the block length is two
  2345. bytes too short.  The following table gives the number of bytes reported and
  2346. the number of actual bytes in the sector:
  2347.  
  2348. . Actual   |    4    |    3    |    2    |    1    |    0    |
  2349. . ---------+---------+---------+---------+---------+---------+
  2350. . Reported |    2    |    1    |    0    |   255   |   255   |
  2351.  
  2352. This is where I ran into problems with Zed-128; the logic of my program
  2353. screwed up on a zero length.  I have corrected the problem here, though.  This
  2354. bug is bizarre because it only happens if the first sector is the only sector
  2355. in the file.  The reported length for all subsequent sectors is correct.  Note
  2356. also that 255 is reported for lengths of both 1 and 0.  This is because there
  2357. is no actual zero length for Commodore files.  If you OPEN1,8,2,"EMPTY" and
  2358. then immediately CLOSE1 you get a file with one carriage return character in
  2359. it.
  2360.  
  2361. The open routine calls the read routine to read a sector and if it was the
  2362. only sector of the file, the two additional bytes are burst-read and put into
  2363. the data buffer.  Note that incrementing the reported count of 255 twice gives
  2364. the correct count of 1.  Also interesting in this case is that when the
  2365. 1571/81 reports the 255, it actually transfers 255 bytes of data, all of which
  2366. are bogus.  It seems to me that they made the 1581 bug-compatible with the
  2367. 1571 in this respect.
  2368.  
  2369. The open routine also executes a SEI for reasons discussed above.  The
  2370. information returned by the open call is the same as what is returned for the
  2371. "burstRead" call discussed next.
  2372.  
  2373. 3.2. BURST READ
  2374.  
  2375. Once the Fastload command is started, the drive starts waiting to transfer the
  2376. data to you.  The transfer occurs sector by sector, with each sector preceeded
  2377. by a burst status byte.  The data is transferred using the shift register of
  2378. CIA#1 and the handshaking is done using the Slow Serial Clock line of CIA#2.
  2379. To receive a byte, you toggle the Slow Serial Clock line and wait for the
  2380. Shift Register Ready signal from CIA#1 and then read the data value from the
  2381. shift data register.
  2382.  
  2383. One of the clock registers in the CIA in the 1571/81 is used as the baud rate
  2384. generator for the serial line.  I think that it uses a delay of 4 microseconds
  2385. per bit, which gives a baud rate of 250,000 (31.25K/sec).  In my
  2386. experimentation, the maximum baud rate I have ever achieved in reality is
  2387. 200,000 (25K/sec).  I read in my 1571 Internals book that the 250,000 baud
  2388. rate cannot actually be achieved because of electrical problems that I don't
  2389. understand.  This is an important difference because the data comes flying off
  2390. the surface of the disk at around 30K/sec and if the serial bus were fast
  2391. enough, it could be transferred to the computer as it is being read.  Some
  2392. things would be so much more convenient if whomever created the universe had
  2393. thought to make light go just a little bit faster.
  2394.  
  2395. The burst handshaking protocol slows the maximum transfer rate down to about
  2396. 16K/sec.  Of course, the disk drive has more things to keep on top of than
  2397. just transferring data, so the actual burst throughput is lower than that:
  2398. about 5.4K/sec with my JiffyDOS-ified 1571 and about 7K/sec with a 1581.  Note
  2399. that you can probably increase your 1571's burst performance a bit by setting
  2400. it to use a sector interleave factor of 4, using the "U0>S"+CHR$(i) burst
  2401. command.  By default, a 1571 writes files with an interleave of 6.
  2402.  
  2403. All of the sectors before the last one will contain 254 bytes of data and the
  2404. last one will contain a specified number of bytes, from 1 to 254.  The status
  2405. code returned for the last sector is value $1F.  In this case, an additional
  2406. byte is sent before the data bytes that tells how many data bytes there will
  2407. be.  This is the value that is bugged for one-sector files as described in the
  2408. last section.  For those who like pictures, here are diagrams of the data
  2409. transferred for a sector:
  2410.  
  2411. .        REGULAR SECTOR                  LAST SECTOR OF FILE
  2412. .     +-------------------+             +--------------------+
  2413. .   0 | Burst Status Byte |           0 | Burst Status = $1F |
  2414. .     +-------------------+             +--------------------+
  2415. .   1 |                   |           1 |   Byte Count = N   |
  2416. . ... +  254 Data Bytes   |             +--------------------+
  2417. . 254 |                   |           2 |                    |
  2418. .     +-------------------+         ... |    N Data Bytes    |
  2419. .                                   N+1 |                    |
  2420. .                                       +--------------------+
  2421.  
  2422. If a sector returns a burst status code other than 0 (ok) or $1F (end), then
  2423. an error has occurred and the disk drive aborts the transfer, closes the burst
  2424. connection, and starts the drive light blinking.
  2425.  
  2426. The "burstRead" call of this package reads the data of the next sector of the
  2427. opened file into the "burstBuf" and returns the "burstStatus" and
  2428. "burstBufCount" (bytes read).  In the event of an error occuring, this routine
  2429. returns with the carry flag set and the translated burst error code in the .A
  2430. register (same as burstOpen).  When the last sector of the file has just been
  2431. read, this routine returns with a value of $1F in the "burstStatus" variable.
  2432.  
  2433. 3.3. BURST CLOSE
  2434.  
  2435. After reading the last data byte of the last sector of the file, the burst
  2436. connection and is closed automatically by the disk drive.  The "burstClose"
  2437. routine is not necessary for communication with the disk drive, but is
  2438. provided for completeness and to clear the interrupt disable bit (CLI) that
  2439. the open routine set to prevent interrupts while burst reading.
  2440.  
  2441. 3.4. PACKAGE USAGE
  2442.  
  2443. The following pseudo-code outlines how a user program is expected to use the
  2444. burst reading package:
  2445.  
  2446. .     jsr put_filename_into_burstBuf
  2447. .     ldx #filename_length
  2448. .     lda #device_number
  2449. .     jsr burstOpen
  2450. .     bcs reportError
  2451. . L1: jsr process_burstBuf_data
  2452. .     lda burstStatus
  2453. .     cmp #$1f
  2454. .     beq L2
  2455. .     jsr burstRead
  2456. .     bcc L1
  2457. .     jsr reportError
  2458. . L2: jsr burstClose
  2459.  
  2460. 4. IMPLEMENTATION
  2461.  
  2462. This section discusses the code that implements the word counting program.  It
  2463. is here in a special form; each code line is preceeded by a few special
  2464. characters and the line number.  The special characters are there to allow you
  2465. to easily extract the assembler code from the rest of this magazine (and all
  2466. of my ugly comments).  On a Unix system, all you have to do is execute the
  2467. following command line (substitute filenames as appropriate):
  2468.  
  2469. grep '^\.%...\!' Hack3 | sed 's/^.%...\!..//' | sed 's/.%...\!//' >wc.asm
  2470.  
  2471.                        
  2472. .%001!  ;Word Count utility using the burst command set's Fastload facility
  2473. .%002!  ;written 92/06/25 by Craig Bruce for C= Hacking Net Magazine
  2474. .%003!
  2475.  
  2476. The code is written for the Buddy assembler and here are a few setup
  2477. directives.
  2478.  
  2479. .%004!  .mem
  2480. .%005!  .bank 15
  2481. .%006!  .org $1c01
  2482. .%007!
  2483. .%008!  ;*** BASIC startup code
  2484. .%009!
  2485.  
  2486. This is what the "10 sys 7200" in BASIC looks like.  It is here so this
  2487. program can be executed with BASIC RUN command.
  2488.  
  2489. .%010!  .word $1c1c
  2490. .%011!  .word 10
  2491. .%012!  .byte $9e
  2492. .%013!  .asc  " 7200 : "
  2493. .%014!  .byte $8f
  2494. .%015!  .asc  " 6502 power!"
  2495. .%016!  .byte 0
  2496. .%017!  .word 0
  2497. .%018!  .word 0
  2498. .%019!
  2499. .%020!  jmp main
  2500. .%021!
  2501. .%022!  ;========== burst read library ==========
  2502. .%023!
  2503. .%024!  burstStatus = $fe
  2504. .%025!  burstBufCount = $ff
  2505. .%026!  burstBuf = $b00
  2506.  
  2507. "serialFlag" is used to determine whether a device is Fast or not, and the
  2508. "ioStatus" (a.k.a. "ST") is to tell if a device is present or not.
  2509.  
  2510. .%027!  serialFlag = $a1c
  2511. .%028!  ioStatus = $90
  2512.  
  2513. "ciaIcr" is the interrupt control register of CIA#1.  It is polled to wait for
  2514. data becoming available in the shift register ("ciaData").  "ciaSerialClk" is
  2515. the Slow serial bus clock line that is used for handshaking on the Fast bus.
  2516.  
  2517. .%029!  ciaIcr = $dc0d
  2518. .%030!  ciaSerialClk = $dd00
  2519. .%031!  ciaData = $dc0c
  2520. .%032!
  2521. .%033!  kernelListen = $ffb1
  2522. .%034!  kernelSecond = $ff93
  2523. .%035!  kernelCiout  = $ffa8
  2524. .%036!  kernelUnlsn  = $ffae
  2525. .%037!  kernelSpinp  = $ff47
  2526. .%038!
  2527.  
  2528. This is the error code value this package returns if it detects that a device
  2529. is not Fast.
  2530.  
  2531. .%039!  errNotBurstDevice = 10
  2532. .%040!
  2533. .%041!  burstFilenameLen = burstBufCount
  2534. .%042!
  2535. .%043!  burstOpen = * ;(.A=Device, burstBuf=Filename, .X=NameLen):<first block>
  2536.  
  2537. Set up for a burst open: clear the Fast flag and the device not present flag.
  2538.  
  2539. .%044!     stx burstFilenameLen
  2540. .%045!     pha
  2541. .%046!     lda serialFlag
  2542. .%047!     and #%10111111
  2543. .%048!     sta serialFlag
  2544. .%049!     lda #0
  2545. .%050!     sta ioStatus
  2546. .%051!     pla
  2547.  
  2548. Command the disk device to Listen.  Then check if the device is present or not
  2549. (bit 7 of ioStatus).  If not present, return the kernel error code.
  2550.  
  2551. .%052!     jsr kernelListen
  2552. .%053!     bit ioStatus
  2553. .%054!     bpl +
  2554. .%055!
  2555. .%056!     devNotPresent = *
  2556. .%057!     jsr kernelUnlsn
  2557. .%058!     lda #5
  2558. .%059!     sec
  2559. .%060!     rts
  2560. .%061!
  2561.  
  2562. Tell disk device to listen on the command channel (channel #15).
  2563.  
  2564. .%062!  +  lda #$6f
  2565. .%063!     jsr kernelSecond
  2566.  
  2567. Send the "U0"+CHR$(159) burst command header.
  2568.  
  2569. .%064!     lda #"u"
  2570. .%065!     jsr kernelCiout
  2571. .%066!     bit ioStatus
  2572. .%067!     bmi devNotPresent
  2573. .%068!     lda #"0"
  2574. .%069!     jsr kernelCiout
  2575. .%070!     lda #$9f
  2576. .%071!     jsr kernelCiout
  2577.  
  2578. Send the filename.
  2579.  
  2580. .%072!     ldy #0
  2581. .%073!  -  lda burstBuf,y
  2582. .%074!     jsr kernelCiout
  2583. .%075!     iny
  2584. .%076!     cpy burstFilenameLen
  2585. .%077!     bcc -
  2586.  
  2587. Finish sending the burst command and make sure the device is Fast.
  2588.  
  2589. .%078!     jsr kernelUnlsn
  2590. .%079!     lda serialFlag
  2591. .%080!     and #$40
  2592. .%081!     bne +
  2593. .%082!     sec
  2594. .%083!     lda #errNotBurstDevice
  2595. .%084!     rts
  2596. .%085!
  2597.  
  2598. Disable interrupts.
  2599.  
  2600. .%086!  +  sei
  2601.  
  2602. Prepare to receive data and signal the disk drive to start sending (by
  2603. toggling the slow serial Clock line).
  2604.  
  2605. .%087!     clc
  2606. .%088!     jsr kernelSpinp
  2607. .%089!     bit ciaIcr
  2608. .%090!     lda ciaSerialClk
  2609. .%091!     eor #$10
  2610. .%092!     sta ciaSerialClk
  2611.  
  2612. Read the first sector of the file.
  2613.  
  2614. .%093!     jsr burstRead
  2615.  
  2616. Check for errors.  Burst error code 2 (file not found) is translated to its
  2617. kernel equivalent.
  2618.  
  2619. .%094!     lda burstStatus
  2620. .%095!     cmp #2
  2621. .%096!     bcc +
  2622. .%097!     bne shortFile
  2623. .%098!     sec
  2624. .%099!     lda #4
  2625. .%100!  +  rts
  2626. .%101!
  2627.  
  2628. Check if this is a one-block file.
  2629.  
  2630. .%102!     shortFile = *
  2631. .%103!     cmp #$1f
  2632. .%104!     bne openError
  2633. .%105!     ldy burstBufCount
  2634. .%106!     ldx #2
  2635. .%107!
  2636.  
  2637. If so, we have to read the two bytes that the disk drive forgot to tell us
  2638. about.  For each byte, we wait for for the Shift Register Ready signal, toggle
  2639. the clock, and read the shift data register.  I can get away with reading the
  2640. data register after sending the acknowledge signal to the disk drive because I
  2641. am running with interrupts disabled and it could not possibly send the next
  2642. byte before I pick up the current one.  We wouldn't want any NMIs happening
  2643. while doing this, though.
  2644.  
  2645. .%108!     shortFileByte = *
  2646. .%109!     lda #$08
  2647. .%110!  -  bit ciaIcr
  2648. .%111!     beq -
  2649. .%112!     lda ciaSerialClk
  2650. .%113!     eor #$10
  2651. .%114!     sta ciaSerialClk
  2652. .%115!     lda ciaData
  2653. .%116!     sta burstBuf,y
  2654. .%117!     iny
  2655. .%118!     dex
  2656. .%119!     bne shortFileByte
  2657.  
  2658. Store the updated byte count and exit.
  2659.  
  2660. .%120!     sty burstBufCount
  2661. .%121!     clc
  2662. .%122!     rts
  2663. .%123!
  2664.  
  2665. In the event of a burst error, re-enable the interrupts since the user might
  2666. not call the burstClose routine.  Return the translated error code.
  2667.  
  2668. .%124!     openError = *
  2669. .%125!     cli
  2670. .%126!     sec
  2671. .%127!     ora #$10
  2672. .%128!     rts
  2673. .%129!
  2674.  
  2675. Read the next sector of the file.
  2676.  
  2677. .%130!  burstRead = * ;( ) : burstBuf, burstBufCount, burstStatus
  2678.  
  2679. Wait for the status byte to arrive.
  2680.  
  2681. .%131!     lda #8
  2682. .%132!  -  bit ciaIcr
  2683. .%133!     beq -
  2684.  
  2685. Toggle clock line for acknowledge.
  2686.  
  2687. .%134!     lda ciaSerialClk
  2688. .%135!     eor #$10
  2689. .%136!     sta ciaSerialClk
  2690.  
  2691. Get status byte and check.  If 2 or more and not $1F, then an error has
  2692. occurred.  If 0, then prepare to read 254 data bytes.
  2693.  
  2694. .%137!     lda ciaData
  2695. .%138!     sta burstStatus
  2696. .%139!     ldx #254
  2697. .%140!     cmp #2
  2698. .%141!     bcc actualRead
  2699. .%142!     cmp #$1f
  2700. .%143!     bne openError
  2701.  
  2702. If status byte is $1F, then get the next byte, which tells how many data bytes
  2703. are to follow.
  2704.  
  2705. .%144!     lda #8
  2706. .%145!  -  bit ciaIcr
  2707. .%146!     beq -
  2708. .%147!     ldx ciaData
  2709. .%148!     lda ciaSerialClk
  2710. .%149!     eor #$10
  2711. .%150!     sta ciaSerialClk
  2712. .%151!
  2713. .%152!     actualRead = *
  2714. .%153!     stx burstBufCount
  2715. .%154!     ldy #0
  2716. .%155!
  2717.  
  2718. Read the data bytes and put them into the burst buffer.  The clock line toggle
  2719. value is computed before receiving the data for a little extra zip.  I haven't
  2720. experimented with this, but you might be able to toggle the clock line before
  2721. receiving the data (however, probably not for the first byte).
  2722.  
  2723. .%156!     readByte = *
  2724. .%157!     lda ciaSerialClk
  2725. .%158!     eor #$10
  2726. .%159!     tax
  2727. .%160!     lda #8
  2728. .%161!  -  bit ciaIcr
  2729. .%162!     beq -
  2730. .%163!     stx ciaSerialClk
  2731. .%164!     lda ciaData
  2732. .%165!     sta burstBuf,y
  2733. .%166!     iny
  2734. .%167!     cpy burstBufCount
  2735. .%168!     bne readByte
  2736. .%169!  +  clc
  2737. .%170!     rts
  2738. .%171!
  2739.  
  2740. Close the burst package: simply CLI.
  2741.  
  2742. .%172!  burstClose = *
  2743. .%173!     cli
  2744. .%174!     clc
  2745. .%175!     rts
  2746. .%176!
  2747. .%177!  ;========== main program ==========
  2748. .%178!
  2749.  
  2750. This is the word counting application code.
  2751.  
  2752. .%179!  bkWC = $0e
  2753. .%180!  bkSelect = $ff00
  2754. .%181!  kernelChrin  = $ffcf
  2755. .%182!  kernelChrout = $ffd2
  2756. .%183!
  2757.  
  2758. The "wcInWord" is a boolean variable that tells whether the file scanner is
  2759. currently in a word or not.  The Lines, Words, and Bytes are 24-bit counters.
  2760.  
  2761. .%184!  wcInWord = 2 ;(1)
  2762. .%185!  wcLines = 3  ;(3)
  2763. .%186!  wcWords = 6  ;(3)
  2764. .%187!  wcBytes = 9  ;(3)
  2765. .%188!
  2766. .%189!  main = *
  2767.  
  2768. Put the kernel ROM and I/O space into context then initialize the counting
  2769. variables.
  2770.  
  2771. .%190!     lda #bkWC
  2772. .%191!     sta bkSelect
  2773. .%192!     jsr wcInit
  2774.  
  2775. Follow the burst reading procedure outline.
  2776.  
  2777. .%193!     jsr wcGetFilename
  2778. .%194!     jsr burstOpen
  2779. .%195!     bcc +
  2780. .%196!     jsr reportError
  2781. .%197!     rts
  2782. .%198!  /  jsr wcScanBuffer
  2783. .%199!     lda burstStatus
  2784. .%200!     cmp #$1f
  2785. .%201!     beq +
  2786. .%202!     jsr burstRead
  2787. .%203!     bcc -
  2788. .%204!     jsr reportError
  2789. .%205!  +  jsr burstClose
  2790.  
  2791. Report the numbers of lines, words, and characters and then exit.
  2792.  
  2793. .%206!     jsr wcReport
  2794. .%207!     rts
  2795. .%208!
  2796.  
  2797. Initialize the variables.
  2798.  
  2799. .%209!  wcInit = *
  2800. .%210!     lda #0
  2801. .%211!     ldx #8
  2802. .%212!  -  sta wcLines,x
  2803. .%213!     dex
  2804. .%214!     bpl -
  2805. .%215!     sta wcInWord
  2806. .%216!     rts
  2807. .%217!
  2808.  
  2809. Get the device and filename from the user.  Returns parameters suitable for
  2810. passing to burstOpen.
  2811.  
  2812. .%218!  wcGetFilename = * ;() : burstBuf=Filename, .A=Device, .X=FilenameLen
  2813.  
  2814. Display the prompt.
  2815.  
  2816. .%219!     ldx #0
  2817. .%220!  -  lda promptMsg,x
  2818. .%221!     beq +
  2819. .%222!     jsr kernelChrout
  2820. .%223!     inx
  2821. .%224!     bne -
  2822.  
  2823. Get the input line from the user.
  2824.  
  2825. .%225!  +  ldx #0
  2826. .%226!  -  jsr kernelChrin
  2827. .%227!     sta burstBuf,x
  2828. .%228!     cmp #13
  2829. .%229!     beq +
  2830. .%230!     inx
  2831. .%231!     bne -
  2832. .%232!  +  jsr kernelChrout
  2833.  
  2834. Extract the device number from the start of the input line.  If it is not
  2835. there, assume device number 8.
  2836.  
  2837. .%233!     lda #8
  2838. .%234!     cpx #2
  2839. .%235!     bcc filenameExit
  2840. .%236!     ldy burstBuf+1
  2841. .%237!     cpy #":"
  2842. .%238!     bne filenameExit
  2843. .%239!     sec
  2844. .%240!     lda burstBuf
  2845. .%241!     sbc #"a"-8
  2846. .%242!     tay
  2847.  
  2848. If a device name was present, then we have to move the rest of the filename
  2849. back over it now that we've extracted it.
  2850.  
  2851. .%243!     ldx #0
  2852. .%244!  -  lda burstBuf+2,x
  2853. .%245!     sta burstBuf,x
  2854. .%246!     cmp #13
  2855. .%247!     beq +
  2856. .%248!     inx
  2857. .%249!     bne -
  2858. .%250!  +  tya
  2859. .%251!     filenameExit = *
  2860. .%252!     rts
  2861. .%253!
  2862. .%254!     promptMsg = *
  2863. .%255!     .asc "enter filename in form filename, or a:filename, "
  2864. .%256!     .asc "or b:filename, ..."
  2865. .%257!     .byte 13
  2866. .%258!     .asc "where 'a' is for device 8, 'b' is for device 9, ..."
  2867. .%259!     .byte 13,0
  2868. .%260!
  2869.  
  2870. Scan the burst buffer after reading a sector into it.
  2871.  
  2872. .%261!  wcScanBuffer = *
  2873. .%262!     ldy #0
  2874. .%263!     cpy burstBufCount
  2875. .%264!     bne +
  2876. .%265!     rts
  2877. .%266!  +  ldx wcInWord
  2878. .%267!  -  lda burstBuf,y
  2879. .%268!  ;   jsr kernelChrout  ;uncomment this line to echo the data read
  2880. .%269!     cmp #13
  2881. .%270!     bne +
  2882.  
  2883. If the current character is a carriage return, then increment the line count.
  2884.  
  2885. .%271!     inc wcLines
  2886. .%272!     bne +
  2887. .%273!     inc wcLines+1
  2888. .%274!     bne +
  2889. .%275!     inc wcLines+2
  2890.  
  2891. If the character is a TAB, SPACE, or a RETURN, then it is a Delimiter;
  2892. otherwise, it is considered a Letter.
  2893.  
  2894. .%276!  +  cmp #33
  2895. .%277!     bcs isLetter
  2896. .%278!     cmp #" "
  2897. .%279!     beq isDelimiter
  2898. .%280!     cmp #13
  2899. .%281!     beq isDelimiter
  2900. .%282!     cmp #9
  2901. .%283!     beq isDelimiter
  2902. .%284!
  2903. .%285!     isLetter = *
  2904.  
  2905. If the character is a Letter and the previous one was a Delimiter, then
  2906. increment the word count.
  2907.  
  2908. .%286!     cpx #1
  2909. .%287!     beq scanCont
  2910. .%288!     ldx #1
  2911. .%289!     inc wcWords
  2912. .%290!     bne scanCont
  2913. .%291!     inc wcWords+1
  2914. .%292!     bne scanCont
  2915. .%293!     inc wcWords+2
  2916. .%294!     jmp scanCont
  2917. .%295!
  2918. .%296!     isDelimiter = *
  2919. .%297!     ldx #0
  2920. .%298!
  2921. .%299!     scanCont = *
  2922. .%300!     iny
  2923. .%301!     cpy burstBufCount
  2924. .%302!     bcc -
  2925.  
  2926. Add the number of bytes in the burst buffer to the total byte count for the
  2927. file.
  2928.  
  2929. .%303!     clc
  2930. .%304!     lda wcBytes
  2931. .%305!     adc burstBufCount
  2932. .%306!     sta wcBytes
  2933. .%307!     bcc +
  2934. .%308!     inc wcBytes+1
  2935. .%309!     bne +
  2936. .%310!     inc wcBytes+2
  2937. .%311!  +  stx wcInWord
  2938. .%312!     rts
  2939. .%313!
  2940.  
  2941. Report the number of lines, words, and bytes read.  Uses a "printf" type of
  2942. scheme.
  2943.  
  2944. .%314!  wcReport = *
  2945. .%315!     ldx #0
  2946. .%316!  -  lda reportMsg,x
  2947. .%317!     beq reportExit
  2948. .%318!     cmp #13
  2949. .%319!     bcs +
  2950. .%320!     stx 14
  2951. .%321!     tax
  2952. .%322!     lda 2,x
  2953. .%323!     sta 15
  2954. .%324!     lda 0,x
  2955. .%325!     ldy 1,x
  2956. .%326!     ldx 15
  2957. .%327!     jsr putnum
  2958. .%328!     ldx 14
  2959. .%329!     jmp reportCont
  2960. .%330!  +  jsr kernelChrout
  2961. .%331!     reportCont = *
  2962. .%332!     inx
  2963. .%333!     bne -
  2964. .%334!     reportExit = *
  2965. .%335!     rts
  2966. .%336!
  2967. .%337!     reportMsg = *
  2968. .%338!     .byte 13
  2969. .%339!     .asc "lines="
  2970. .%340!     .byte wcLines
  2971. .%341!     .asc ", words="
  2972. .%342!     .byte wcWords
  2973. .%343!     .asc ", chars="
  2974. .%344!     .byte wcBytes,27
  2975. .%345!     .asc "q"
  2976. .%346!     .byte 13,0
  2977. .%347!
  2978.  
  2979. Reports the error number given in the .A register.  Called after an error is
  2980. returned from a burst routine.
  2981.  
  2982. .%348!  reportError = * ;( .A=errNum )
  2983. .%349!     pha
  2984. .%350!     ldx #0
  2985. .%351!  -  lda errorMsg,x
  2986. .%352!     beq +
  2987. .%353!     jsr kernelChrout
  2988. .%354!     inx
  2989. .%355!     bne -
  2990. .%356!  +  pla
  2991. .%357!     ldy #0
  2992. .%358!     ldx #0
  2993. .%359!     jsr putnum
  2994. .%360!     lda #13
  2995. .%361!     jsr kernelChrout
  2996. .%362!     rts
  2997. .%363!
  2998. .%364!     errorMsg = *
  2999. .%365!     .asc "*** i/o error #"
  3000. .%366!     .byte 0
  3001. .%367!
  3002. .%368!  ;==========library==========
  3003. .%369!
  3004.  
  3005. Routine to print out the 24-bit number given in .AYX.
  3006.  
  3007. .%370!  libwork = $60
  3008. .%371!  itoaBin = libwork
  3009. .%372!  itoaBcd = libwork+3
  3010. .%373!  itoaFlag = libwork+7
  3011. .%374!
  3012. .%375!  putnum = *
  3013.  
  3014. Initialize binary and BCD (Binary Coded Decimal) representations of number.
  3015.  
  3016. .%376!     sta itoaBin+0
  3017. .%377!     sty itoaBin+1
  3018. .%378!     stx itoaBin+2
  3019. .%379!     ldx #3
  3020. .%380!     lda #0
  3021. .%381!  -  sta itoaBcd,x
  3022. .%382!     dex
  3023. .%383!     bpl -
  3024. .%384!     sta itoaFlag
  3025. .%385!     ldy #24
  3026. .%386!     sed
  3027. .%387!
  3028.  
  3029. Rotate each bit out of the binary number and then multiply the BCD number by
  3030. two and add the bit in.  Effectively, we are shifting the bits out of the
  3031. binary number and into the BCD representation of the number.
  3032.  
  3033. .%388!     itoaNextBit = *
  3034. .%389!     asl itoaBin+0
  3035. .%390!     rol itoaBin+1
  3036. .%391!     rol itoaBin+2
  3037. .%392!     ldx #3
  3038. .%393!  -  lda itoaBcd,x
  3039. .%394!     adc itoaBcd,x
  3040. .%395!     sta itoaBcd,x
  3041. .%396!     dex
  3042. .%397!     bpl -
  3043. .%398!     dey
  3044. .%399!     bne itoaNextBit
  3045. .%400!     cld
  3046.  
  3047. Take the BCD bytes and spit out the two digits they contain.
  3048.  
  3049. .%401!     ldx #0
  3050. .%402!     ldy #0
  3051. .%403!  -  lda itoaBcd,x
  3052. .%404!     jsr itoaPutHex
  3053. .%405!     inx
  3054. .%406!     cpx #4
  3055. .%407!     bcc -
  3056. .%408!     rts
  3057. .%409!
  3058. .%410!     itoaPutHex = *
  3059. .%411!     pha
  3060. .%412!     lsr
  3061. .%413!     lsr
  3062. .%414!     lsr
  3063. .%415!     lsr
  3064. .%416!     jsr itoaPutDigit
  3065. .%417!     pla
  3066. .%418!     and #$0f
  3067. .%419!
  3068.  
  3069. Print out the individual digits of the number.  If the current digit is zero
  3070. and all digits so far have been zero, then don't output anything, unless it is
  3071. the last digit of the number.
  3072.  
  3073. .%420!     itoaPutDigit = *
  3074. .%421!     cmp itoaFlag
  3075. .%422!     bne +
  3076. .%423!     cpy #7
  3077. .%424!     bcc itoaPutDigitExit
  3078. .%425!  +  ora #$30
  3079. .%426!     sta itoaFlag
  3080. .%427!     jsr kernelChrout
  3081. .%428!     itoaPutDigitExit = *
  3082. .%429!     iny
  3083. .%430!     rts
  3084.  
  3085. 5. UUENCODED PROGRAM
  3086.  
  3087. Here is the binary executable in uuencoded form.  The CRC32 of it is
  3088. 3676144922.  LOAD and RUN it like a regular BASIC program.
  3089.  
  3090. begin 640 wc
  3091. M`1P<'`H`GB`W,C`P(#H@CR`V-3`R(%!/5T52(0``````3!$=AO](K1P**;^-
  3092. M'`JI`(60:""Q_R20$`<@KO^I!3A@J6\@D_^I52"H_R20,.NI,""H_ZF?(*C_
  3093. MH`"Y``L@J/_(Q/^0]2"N_ZT<"BE`T`0XJ0I@>!@@1_\L#=RM`-U)$(T`W2"]
  3094. M'*7^R0*0!=`$.*D$8,D?T"&D_Z("J0@L#=SP^ZT`W4D0C0#=K0S<F0`+R,K0
  3095. MYX3_&&!8.`D08*D(+`W<\/NM`-U)$(T`W:T,W(7^HO[)`I`6R1_0W:D(+`W<
  3096. M\/NN#-RM`-U)$(T`W8;_H`"M`-U)$*JI""P-W/#[C@#=K0S<F0`+R,3_T.48
  3097. M8%@88*D.C0#_(#T=($D=(",<D`0@H!Y@(`4>I?[)'_`((+T<D/(@H!X@#AT@
  3098. M6QY@J0"B")4#RA#[A0)@H@"]C1WP!B#2_^C0]:(`(,__G0`+R0WP`^C0\R#2
  3099. MLZD(X`*0'JP!"\`ZT!<XK0`+Z3FHH@"]`@N=``O)#?`#Z-#SF&!%3E1%4B!&
  3100. M24Q%3D%-12!)3B!&3U)-($9)3$5.04U%+"!/4B!!.D9)3$5.04U%+"!/4B!"
  3101. M.D9)3$5.04U%+"`N+BX-5TA%4D4@)T$G($E3($9/4B!$159)0T4@."P@)T(G
  3102. M($E3($9/4B!$159)0T4@.2P@+BXN#0"@`,3_T`%@I@*Y``O)#=`*Y@/0!N8$
  3103. MT`+F!<DAL`S)(/`;R0WP%\D)\!/@`?`1H@'F!M`+Y@?0!^8(3$0>H@#(Q/^0
  3104. MQ1BE"67_A0F0!N8*T`+F"X8"8*(`O8(>\!_)#;`5A@ZJM0*%#[4`M`&F#R#,
  3105. M'J8.3'X>(-+_Z-#<8`U,24Y%4ST#+"!73U)$4ST&+"!#2$%24ST)&U$-`$BB
  3106. M`+V\'O`&(-+_Z-#U:*``H@`@S!ZI#2#2_V`J*BH@22]/($524D]2(",`A6"$
  3107. M889BH@.I`)5CRA#[A6>@&/@&8"9A)F*B`[5C=6.58\H0]XC0[-BB`*``M6,@
  3108. D!!_HX`20]F!(2DI*2B`/'V@I#\5GT`3`!Y`'"3"%9R#2_\A@````
  3109. `
  3110. end
  3111.  
  3112. 6. REFERENCES
  3113.  
  3114. [1] Commodore Business Machines, _Commodore_1571_Disk_Drive_User's_Guide_,
  3115.     CBM, 1985.
  3116.  
  3117. [2] Rainer Ellinger, _1571_Internals_, Abacus Software, June 1986.
  3118.  
  3119. ===============================================================================
  3120. Next Issue: (hopefully!)
  3121.  
  3122. Learning ML - Part 4
  3123.  
  3124.   In the next issue we'll embark on a project of making a space invaders style
  3125. game for the C=64/128 using the KERNAL routines we've learned.
  3126.  
  3127. The Demo Corner: FLI - more color to the screen
  3128.  
  3129.   All of us have heard complaints about the color constraints on C64.
  3130. FLI picture can have all of the 16 colors in one char position. What then
  3131. is this FLI and how it is done ?
  3132.  
  3133. The 1351 Mouse Demystified
  3134.  
  3135.   An indepth look at how the 1351 mouse operates and how to access it within
  3136. your own ML programs.  For Basic programmers, a driver for the 80 column screen
  3137. is also supplied. 
  3138.  
  3139. LITTLE RED READER: MS-DOS file reader for the 128 and 1571/81 drives.
  3140.  
  3141. This article will present a package that reads MS-DOS files and the root
  3142. directory of MS-DOS disks.  This package will use the dynamic memory allocation
  3143. package introduced in Hacking Issue #2 to allow large files to be read in.
  3144. The application-level code hasn't been finalized yet, but it will probably use
  3145. a menu-oriented full-screen display and will read and translate MS-DOS and
  3146. Commodore files. 
  3147. =============================================================================
  3148. END of Commodore Hacking Issue 3.
  3149. =============================================================================
  3150.  
  3151.