0

I've been playing on my recently resurrected Apple IIs, a //e, IIc, and IIgs (mostly the //e), tinkering with assembly.

I'm reading the paddles and plotting a colored block on the screen, kind of an Etch a Sketch, and I thought I would mix in some text and display the hex value of the paddle read.

I know it's fairly trivial in BASIC but I cannot move the cursor to the text lines to display the output of PRBYTE($FDDA). CH = $24, CV = $25, horizontal placement works but vertical placement not at all.

I don't know what I'm doing wrong and then again I may be going about the whole thing mistakenly. My code, such as it is, follows. I apologize if it is more than I should post. I'm hoping for any comments.

                     1    
                     2    ********************************
                     3    *                              *
                     4    *      Draw blocks plotted     *
                     5    *          by paddles          *
                     6    *                              *
                     7    ********************************
                     8    
                     9    
                     10            ORG   $8000      
                     11   
                     13   
            =FC58    14   HOME     EQU   $FC58      ; CURSOR POS
            =C000    15   KYBD     EQU   $C000      ;
            =C010    16   STROBE   EQU   $C010      
            =FDED    17   COUT     EQU   $FDED      
            =FD8E    18   CROUT    EQU   $FD8E      
            =C050    19   TXTOFF   EQU   $C050      ; TEXT OFF
            =C051    20   TXTON    EQU   $C051      ; text on
            =C052    21   MXDOFF   EQU   $C052      ; MIXED OFF
            =C053    22   MXDON    EQU   $C053      ; MIXED ON
            =C056    23   LOWRES   EQU   $C056      ; HIRES OFF
            =F836    24   CLRTOP   EQU   $F836      ; Clear top 40 rows
            =F832    25   CLRSCR   EQU   $F832      ; CLEAR LOWRES
            =F864    26   SETCOL   EQU   $F864      ; SET COLOR
            =F85F    27   NXTCOL   EQU   $F85F      ; Next color
            =F800    28   PLOT     EQU   $F800      ; PLOT A BLOCK
            =FB1E    29   PDLRD    EQU   $FB1E      ; Read paddle
            =0006    30   XAXIS    EQU   $06        ; Store paddle 0 read
            =0007    31   YAXIS    EQU   $07        ; Store paddle 1 read
            =0008    32   BITMSK   EQU   $08        
            =C061    33   PDLBTN0  EQU   $C061      
            =C062    34   PDLBTN1  EQU   $C062      
            =FDDA    35   PRBYTE   EQU   $FDDA      
            =FCA8    36   WAIT     EQU   $FCA8      
            =FE2C    37   MOVE     EQU   $FE2C      
                     38   
            =0024    39   CH       EQU   $24        
            =0025    40   CV       EQU   $25        
                     41   
            =0650    42   XDSPLY   EQU   $0650      
            =0750    43   YDSPLY   EQU   $0750      
                     44   
008000: 20 58 FC     45            JSR   HOME       
008003: AD 56 C0     46   START    LDA   LOWRES     
008006: AD 53 C0     47            LDA   MXDON      
008009: AD 50 C0     48            LDA   TXTOFF     
00800C: 20 36 F8     49            JSR   CLRTOP     
                     50   
00800F: A9 00        51            LDA   #$00       ; BLACK
008011: 20 64 F8     52            JSR   SETCOL     ; SETCOL
                     53   
008014: A2 00        54   ENTRY    LDX   #$00       ; Use paddle 0
008016: A9 00        55   RDPDL0   LDA   #$00       
008018: 20 A8 FC     56            JSR   WAIT       ; 13 cycles
00801B: 20 1E FB     57   CONT0    JSR   PDLRD      
00801E: 98           58            TYA              
00801F: C9 26        59            CMP   #$26       ; $26, 38, Bottom edge in mixed mode
008021: B0 3E =8061  60            BCS   LMT0       ; $2E, 46, Bottom edge mixed mode off
008023: 85 06        61   CNTNU0   STA   XAXIS      
                     62   
008025: A9 00        63   RDPDL1   LDA   #$00       
008027: 20 A8 FC     64            JSR   WAIT       ; 13 cycles
00802A: A2 01        65   CONT1    LDX   #$01       ; Paddle 1
00802C: 20 1E FB     66            JSR   PDLRD      ; Read paddle 1
00802F: 98           67            TYA              
008030: C9 27        68            CMP   #$27       ; 39, Right edge
008032: B0 32 =8066  69            BCS   LMT1       
008034: 85 07        70   CNTNU1   STA   YAXIS      
                     71   
008036: 20 5F F8     72   DRAW     JSR   NXTCOL     ; Next color
008039: F0 FB =8036  73            BEQ   DRAW       ; Exclude black
00803B: A5 06        74            LDA   XAXIS      
00803D: A4 07        75            LDY   YAXIS      
00803F: 20 00 F8     76            JSR   PLOT       
                     77   
008042: A9 80        78            LDA   #%10000000 ; #$80
008044: 2C 61 C0     79            BIT   PDLBTN0    ; High bit set? OA
008047: 30 23 =806C  80            BMI   CLR        ; Yes, clear screen
008049: 2C 62 C0     81            BIT   PDLBTN1    ; High bit set? CA
00804C: 30 38 =8086  82            BMI   END        ; Yes, all done
                     83   
00804E: AD 00 C0     84            LDA   KYBD       
008051: C9 8B        85            CMP   #$8B       ; UP ARROW
008053: 8D 10 C0     86            STA   STROBE     
008056: F0 03 =805B  87            BEQ   DOIT       
                     88   
008058: 4C 14 80     89            JMP   ENTRY      ; Keep reading paddles
                     90   
00805B: 20 11 81     91   DOIT     JSR   PRBYT      
00805E: 4C 14 80     92            JMP   ENTRY      
                     93   
008061: A9 26        94   LMT0     LDA   #$26       ; 38, Bottom edge mixed on
008063: 4C 23 80     95            JMP   CNTNU0     
                     96   
008066: A9 27        97   LMT1     LDA   #$27       ; 39, Right edge
008068: 4C 34 80     98            JMP   CNTNU1     
                     99   
00806B: 60           100           RTS              
                     101  
00806C: 20 36 F8     102  CLR      JSR   CLRTOP     ; Clear top 40 rows lowres
00806F: A9 A0        103           LDA   #$A0       ; and the 4 text lines
008071: 20 8D 80     104           JSR   CLR1       
008074: A9 A0        105           LDA   #$A0       
008076: 20 AE 80     106           JSR   CLR2       
008079: A9 A0        107           LDA   #$A0       
00807B: 20 CF 80     108           JSR   CLR3       
00807E: A9 A0        109           LDA   #$A0       
008080: 20 F0 80     110           JSR   CLR4       
008083: 4C 14 80     111           JMP   ENTRY      
                     112  
                     113  
008086: AD 51 C0     114  END      LDA   TXTON      
                     115  
008089: 20 58 FC     116           JSR   HOME       
                     117  
00808C: 60           118           RTS              
                     119  
00808D: 8D 50 06     120  CLR1     STA   $0650      ;Clear 1st text line
                     121  
008090: A9 51        122           LDA   #$51       
008092: 85 42        123           STA   $0042      ; Dest addr low byte (A4)
008094: A9 06        124           LDA   #$06       
008096: 85 43        125           STA   $0043      ; Dest addr high byte (A4)
008098: A9 50        126           LDA   #$50       
00809A: 85 3C        127           STA   $3C        ; Starting src addr low byte (A1)
00809C: A9 06        128           LDA   #$06       
00809E: 85 3D        129           STA   $3D        ; Starting src addr high byte (A1)
0080A0: A9 77        130           LDA   #$77       
0080A2: 85 3E        131           STA   $3E        ; Ending src addr low byte (A2)
0080A4: A9 06        132           LDA   #$06       
0080A6: 85 3F        133           STA   $3F        ; Ending src addr high byte (A2)
                     134  
0080A8: A0 00        135           LDY   #$00       
0080AA: 20 2C FE     136           JSR   MOVE       
                     137  
0080AD: 60           138           RTS              
                     139  
                     140  
0080AE: 8D D0 06     141  CLR2     STA   $06D0      ; Clear the 2nd text line
                     142  
0080B1: A9 D1        143           LDA   #$D1       
0080B3: 85 42        144           STA   $0042      ; Dest addr low byte (A4)
0080B5: A9 06        145           LDA   #$06       
0080B7: 85 43        146           STA   $0043      ; Dest addr high byte (A4)
0080B9: A9 D0        147           LDA   #$D0       
0080BB: 85 3C        148           STA   $3C        ; Starting src addr low byte (A1)
0080BD: A9 06        149           LDA   #$06       
0080BF: 85 3D        150           STA   $3D        ; Starting src addr high byte (A1)
0080C1: A9 F7        151           LDA   #$F7       
0080C3: 85 3E        152           STA   $3E        ; Ending src addr low byte (A2)
0080C5: A9 06        153           LDA   #$06       
0080C7: 85 3F        154           STA   $3F        ; Ending src addr high byte (A2)
                     155  
0080C9: A0 00        156           LDY   #$00       
0080CB: 20 2C FE     157           JSR   MOVE       
                     158  
0080CE: 60           159           RTS              
                     160  
                     161  
0080CF: 8D 50 07     162  CLR3     STA   $0750      ; Clear the 3rd text line
                     163  
0080D2: A9 51        164           LDA   #$51       
0080D4: 85 42        165           STA   $0042      ; Dest addr low byte (A4)
0080D6: A9 07        166           LDA   #$07       
0080D8: 85 43        167           STA   $0043      ; Dest addr high byte (A4)
0080DA: A9 50        168           LDA   #$50       
0080DC: 85 3C        169           STA   $3C        ; Starting src addr low byte (A1)
0080DE: A9 07        170           LDA   #$07       
0080E0: 85 3D        171           STA   $3D        ; Starting src addr high byte (A1)
0080E2: A9 77        172           LDA   #$77       
0080E4: 85 3E        173           STA   $3E        ; Ending src addr low byte (A2)
0080E6: A9 07        174           LDA   #$07       
0080E8: 85 3F        175           STA   $3F        ; Ending src addr high byte (A2)
                     176  
0080EA: A0 00        177           LDY   #$00       
0080EC: 20 2C FE     178           JSR   MOVE       
                     179  
0080EF: 60           180           RTS              
                     181  
0080F0: 8D D0 07     182  CLR4     STA   $07D0      ; Clear the 4th text line
                     183  
0080F3: A9 D1        184           LDA   #$D1       
0080F5: 85 42        185           STA   $0042      ; Dest addr low byte (A4)
0080F7: A9 07        186           LDA   #$07       
0080F9: 85 43        187           STA   $0043      ; Dest addr high byte (A4)
0080FB: A9 D0        188           LDA   #$D0       
0080FD: 85 3C        189           STA   $3C        ; Starting src addr low byte (A1)
0080FF: A9 07        190           LDA   #$07       
008101: 85 3D        191           STA   $3D        ; Starting src addr high byte (A1)
008103: A9 F7        192           LDA   #$F7       
008105: 85 3E        193           STA   $3E        ; Ending src addr low byte (A2)
008107: A9 07        194           LDA   #$07       
008109: 85 3F        195           STA   $3F        ; Ending src addr high byte (A2)
                     196  
00810B: A0 00        197           LDY   #$00       
00810D: 20 2C FE     198           JSR   MOVE       
                     199  
008110: 60           200           RTS              
                     201  
008111: EA           202  PRBYT    NOP              
008112: A9 1E        203           LDA   #$1E       ; 30
008114: 85 24        204           STA   CH         
008116: A9 14        205           LDA   #$14       ; 20
008118: 85 25        206           STA   CV         
00811A: A5 06        207           LDA   XAXIS      
00811C: 20 DA FD     208           JSR   PRBYTE     
                     209  
00811F: 60           210           RTS              


End Merlin-16 assembly, 288 bytes, 0 errors, 210 lines, 47 symbols.

Elapsed time = 22 seconds.

Symbol table, alphabetical order:

   CH      =$24        CLR     =$806C      CLR1    =$808D      CLR2    =$80AE
   CLR3    =$80CF      CLR4    =$80F0      CLRTOP  =$F836      CNTNU0  =$8023
   CNTNU1  =$8034      CV      =$25        DOIT    =$805B      DRAW    =$8036
   END     =$8086      ENTRY   =$8014      HOME    =$FC58      KYBD    =$C000
   LMT0    =$8061      LMT1    =$8066      LOWRES  =$C056      MOVE    =$FE2C
   MXDON   =$C053      NXTCOL  =$F85F      PDLBTN0 =$C061      PDLBTN1 =$C062
   PDLRD   =$FB1E      PLOT    =$F800      PRBYT   =$8111      PRBYTE  =$FDDA
   SETCOL  =$F864      STROBE  =$C010      TXTOFF  =$C050      TXTON   =$C051
   WAIT    =$FCA8      XAXIS   =$06        YAXIS   =$07     

Symbol table, numerical order:

   XAXIS   =$06        YAXIS   =$07        CH      =$24        CV      =$25
   ENTRY   =$8014      CNTNU0  =$8023      CNTNU1  =$8034      DRAW    =$8036
   DOIT    =$805B      LMT0    =$8061      LMT1    =$8066      CLR     =$806C
   END     =$8086      CLR1    =$808D      CLR2    =$80AE      CLR3    =$80CF
   CLR4    =$80F0      PRBYT   =$8111      KYBD    =$C000      STROBE  =$C010
   TXTOFF  =$C050      TXTON   =$C051      MXDON   =$C053      LOWRES  =$C056
   PDLBTN0 =$C061      PDLBTN1 =$C062      PLOT    =$F800      CLRTOP  =$F836
   NXTCOL  =$F85F      SETCOL  =$F864      PDLRD   =$FB1E      HOME    =$FC58
   WAIT    =$FCA8      PRBYTE  =$FDDA      MOVE    =$FE2C   



1 Answer 1

2

It's not really clear from the code what the window settings are. CH is an absolute line number, while CV is always relative to window width. Any value of CH ($24) / CV ($25) equal or higher to WNDWDTH ($21) / WNDBTM ($23) will reposition the output.


Unless there's a special reason to do everything 'by hand', I would suggest simply calling SETGR ($FB40) and HOME ($FC59) to initialize:

     LDA   LORES    ($C056)
     LDA   MIXSET   ($C053)
     JSR   SETGR    ($FB40)
     JSR   HOME     ($FC58)

After that

  • Lowres is set
  • Mixed mode is set
  • Top is cleared
  • Text window is set to
    • WNDTOP ($22) = 20
    • WNDLFT ($20) = 0
    • WNDWDTH ($21) = 40
    • WNDBTM ($23) = 24
  • Cursor is set to first position within that window

(See the ROM listing for details)

Calling Home afterwards will clear the text window. After that any regular character output will simply go (and stay) within the window set.


Similar to get back to a regular text screen use SETTEXT ($FB39 *1):

     LDA   LORES
     LDA   TXTPAGE1
     JSR   TXTSET   ($FB39)

A good book for all things Apple II low level/Monitor related is

It does a good job in explaining everything the monitor does, all memory locations, all routines and all mechanics.


*1 - I was always amazed how this two addresses are just off by 1, thus easy to remember.

Yes, I know, it's a misconception, but easy to fall for ;)

9
  • So cool, thank you. I was unaware of the $FB40 and $FB39 routines and "Apple II Monitors Peeled". I was relying on the //e reference, no mention is made other than in the the monitor firmware listing which I did refer to trying to figure out PRBYTE which, to me, seems complicated; I could put the value into $06D0 or whatever and clear it but of course the display was in ASCII. How would I display 0D, 00001101, rather than an inverse M? Quite sure then I knew I was trying too hard. Never thought to set the window, wasn't trying to do it "by hand", just didn't know how to make it work.
    – mswade
    Commented Aug 28, 2022 at 23:23
  • Unsure the reference "...amazed ... two addresses ... off by 1 ... misconception, but easy to fall for ..." I'm sorry , I'm not following.
    – mswade
    Commented Aug 28, 2022 at 23:26
  • Also, I need to read the book you referenced but I don't understand "CH is an absolute line number, while CV is always relative to window width. Any value of CH ($24) / CV ($25) equal or higher to WNDBTM ($23) / WNDWDTH ($21) will reposition the output." CV pertains to the rows, yes? CH the columns, no? Why CV always relative to window width? I have to read, and thanks much again.
    – mswade
    Commented Aug 28, 2022 at 23:32
  • 1
    @mswade The are not, The addresses are Hex $FS39 and $FB40 - that's not 1 bye apart but 7 bytes. But our brains are wired to read 39 and 40 as decimal, aren't they? Explaining a joke doesn't make it useful, des it?
    – Raffzahn
    Commented Aug 29, 2022 at 1:03
  • 1
    Apparently my brain is so wired and the joke is on me and I knew the risks of asking you to explain it, yet still good for a laugh; I once forgot 1000 = 1024, still at it
    – mswade
    Commented Aug 29, 2022 at 1:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .