SuperCPU Tutorial Listings - Part 4



Listing 4.1

; 65816
; Clear screen using the stack
; Version 1
; written in 1997 by Malte Mundt
; for GO64!

 £ba $c000                              

          sei

          ldx #$00
          lda #$00
fill:
          sta $0400,x   ; 5 cycles
          sta $0500,x   ; 5
          sta $0600,x   ; 5
          sta $0700,x   ; 5
          dex           ; 2
          bne fill      ; 3
                        ; = 25 total

; 4 bytes are cleared per loop
; 6250 cycles needed

          cli
key:
          jsr $f13e     ; wait for key
          beq key

          sei
          clc           ; native
          xce

          rep #$30      ; a&x/y to 16 bit
 £al                    ; tell assembler
 £rl
          tsx           ; save old stack
          stx oldstack  ; (16 bit)

          ldx #$07e7    ; set stackpointer
          txs           ; to screen-end
                        ; 
          lda #$2020    ; spaces
clear:
          pha           ; 4 cycles
          pha           ; 4

          tsx           ; 2
          cpx #$0400    ; 3
          bcs clear     ; 3
                        ; = 16 total
; 4 bytes per loop
; 4000 cycles

          ldx oldstack  ; reset stack back
          txs           ; to normal
                                        
          sep #$30      ;8 bit
 £as
 £rs
          sec           ;emulation
          xce           ;mode
          cli
          rts

oldstack:
 £wo $0000




Listing 4.2
                                        
; 65816
; Clear screen using the stack
; Version 2
; written in 1997 by Malte Mundt
; for GO64!
                                        
 £ba $c000

          sei
          ldx #$00
          lda #$00
fill:
          sta $0400,x   ; 5 cycles
          sta $0500,x   ; 5
          sta $0600,x   ; 5
          sta $0700,x   ; 5
          dex           ; 2
          bne fill      ; 3
                        ; = 25 total

; 4 bytes are cleared per loop
; 6250 cycles needed

key:
          jsr $f13e     ; wait for key
          beq key

          sei
          clc           ; native
          xce

          rep #$30      ; a&x/y to 16 bit
 £al                    ; tell assembler
 £rl
          cli

          tsc           ; save old stack
          sta oldstack  ; using TSC (Stack to Accu)

          lda #$07e7    ; set stackpointer to
          tcs           ; auf screen-end with TCS (Accu to Stack)

          ldx #$2020    ; spaces
clear:
          phx           ; use x-register this time
          phx

          tsc           ; Stack to Accu
          cmp #$0400    ; done?
          bcs clear     ; no, continue

          lda oldstack  ; reset old stackpointer
          tcs           ; Accu to Stack

          sep #$30      ;8 bit
 £as
 £rs
          sec     ;emulation
          xce     ;mode
          cli
          rts

oldstack:
 £wo $0000




Listing 4.3

; 65816
; 16 Bit Examples
; written in 1997 by Malte Mundt
; for GO64!

 £ba $c000

          sei
          clc             ; clear carry
          xce             ; native mode

          rep #%00110000  ; a,x,y 16 bit
 £al                      ; tell assembler
 £rl

          ldx #$5000
label:
          inx
          bpl label

; Loops to label: until x has reached
; $8000 (last POSITIVE value is $7fff)

          inc testvalue1

; after that inc, testvalue1=$00,
; testvalue1+1 = $01

          asl testwert2

; after that asl, testvalue2 contains
; %00000000, testvalue2+1 contains
; %00000001 - the 7.bit moved to bit 8

          lda #$1000
          sta $fc

; after that sta, $fc conatins $00,
; $fd contains $10

          lda #$0102
          sta $d020

; this sta sets the border to white and the
; background to red

          lda #$2121
          sta $0400

; 2 '!' pop up at the upper left screen

          lda $d800
          ora #%1111111111111111
          sta $d800

; both chars get colored light grey

          sec
          xce
          cli
          rts


testvalue1:
 £by $ff
 £by $00

testvalue2:
 £by %10000000
 £by %00000000




Listing 4.4

; 65816
; Move Zeropage somewhere else - Version 1
; Comment: The Zeropage on SCPU related documents 
; often is called Direct Page aswell.
; written in 1997 by Malte Mundt
; for GO64!

 £ba $c000

          sei
          clc             ; native
          xce

          lda #$74        ; new zp to $7000
          pha             ; push highbyte to stack  
          lda #$00        ; lowbyte             
          pha             ; to stack      
          pld             ; pull stack to direct page register

; from now on the 0-page resides from $7400 - $7500

          ldx #$00
          lda #$21
fill:
          sta $00,x       ; fill new 'zero'-page
          inx
          bne fill

; $7400-$7500 will be filled now and the complete
; old zeropage will stay intact !

; possible ideas for using such stuff as mentioned in
; the tutorial: music players with own zeropage
; and other critical timing stuff.
; Remember: Put you zeropage to a bitmap or color-ram and
; write to it very fast using 2 cycle commands :)

          lda #$00; load zero
          pha     ; push to stack as
          pha     ; high and low byte
          pld     ; revive original zeropage :)

; Direct Page Register now has $0000 and sets up the
; Zeropage from $0000 - $0100

          sec
          xce
          cli
          rts

; Final comment: Try to keep the Low Byte 
; of your new Direct Pages $00.
; else the processor will slow down again, 
; coz it has to calc to get the right
; address.




Listing 4.5

; 65816
; Move Zeropage somewhere else
; Version 2
; written in 1997 by Malte Mundt
; for GO64!

 £ba $c000

          sei
          clc             ; native
          xce

          rep #%00100000  ; accu 16 bit
 £al                      ; tell assembler

          lda #$7400      ; new ZP-Location
          tcd             ; to direct page register

; zeropage now is at $7400-$7500

          sep #%00100000  ; akku 8 bit
 £as                      ; tell ass

          ldx #$00
          lda #$21
fill:
          sta $00,x       ; fill 'zero'-page
          inx
          bne fill

; only $7400-$7500 will get filled

          rep #%00100000  ; accu 16 bit
 £al
          lda #$0000      ; load adress $0000
          tcd             ; restore original ZP

; $0000-$0100 is now the direct page again

          sep #%00100000
 £as
          sec
          xce             ; emulation mode
          cli
          rts

Assembler Code © by Malte Mundt

Partial translation and cosmetical changes by Count Zero/SCS*TRC

[ Listings Part 3 ][ Tutorial Part 4 ][ Index ][ Listings Part 5 ]