˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚% ;example 26 mainline routine screen„ equ 80 Š xref initstd_‹ ; references to Š xref putchar_‹ ; system routines Š xref putnl_ Š xref itos_ Š xref displayŒ ; reference to user routine ˙˙‚ ‡ jsr initstd_Œ ; initialize standard I/O Š ldb numberŽ ; load 25 into B Š jsr hdisplayŒ ; display 25 in hexadecimal Š jsr putnl_Ž ; skip to a new line Š swi number„ fcb ‚ reen‹ ; display "EVEN" Š jsr putnl_Ž ; skip to a new line Š swi scr80… "fcc "This is an 80-column screen" Š fcb 0 scr40… !fcc "This is a 40-column screen" Š fcb 0 leftstrƒ fcc "ODD" Š fcb  Š ldb #'l‘ ; on left side Š prints screen‹ ; display scr80 or scr40 Š jsr putnl_Ž ; skip to a new line Š jsr putnl_Ž ; skip to a new line Š ldx #leftstrŒ ;˙˙‚ ‡ endm” ; end of macro "prints" Š jsr initstd_Œ ; initialize standard I/O Š jsr putnl_Ž ; skip to a new line Š ifeq (screen - 80)† ; if screem equals 80 Ž ldx #scr80ƒ ˙˙‚ † loop ;„ loop ‘ ldb #'‹ ;† load ' ' into B ‘ pshs y‹ ;† save Y ‘ jsr putchar_… ;† display blank ‘ puls y‹ ;† restore Y ‡ ˙˙‚ prints„ macr Š cmpb #'r ; compare B to 'r' Š if eq“ ; if B equals 'r' Ž ifeq \0-80Š ;„ if %0 equals 80 ‘ ldy #40Š ;‡ load Y with 40 Ž endc„ ˙˙‚25 Š end ine routine Š xref initstd_‹ ; references to Š xref putnl_ ; system routines Š xref hdisplay‹ ; reference to user routine Š lds #$0ƒfŽ ; initialize S pointer ƒ g 0 rightstr fcb 8 Š fcb 8 Š fcb 8 Š fcc "EVEN" Š fcb 0 Š end † ; display "ODD" Š ldx #rightstr‹ ; load address of rightstr Š ldb #'r‘ ; on right side Š prints sc  load address of leftstr Š ldb #'l‘ ; on left side Š prints screen‹ ; display "ODD" Š ldx #rightstr‹ ; load address of rightstr Š ldb #'r‘ ; on right side Š prints sc˙˙‚ ‡ ;„ load address of scr80 Š endc” ; end of cond. if Š ifeq (screen - 40)† ; if screen equals 40 Ž ldx #scr40Š ;„ load address of scr40 Š endc” ; end of cond. if˙˙‚ Š leay -1,yˆ ;† decrement Y by 1 Ž until eqŒ ;„ quit if Y equals 0 Ž puls xŽ ;„ restore X Š endif“ ; endif Š jsr display ; display string ƒ ˙˙‚ Œ ;„ end of cond. if Ž ifeq \0-40Š ;„ if %0 equals 40 ‘ ldy #20Š ;‡ load Y with 20 Ž endc ;„ end of cond. if Ž pshs xŽ ;„ save X ˆ  ;example 21 mainline routine Š xref initstd_‹ ; references to Š xref putnl_ ; system routines Š xref length_ Š xref equal_ Š xref displayŒ ; references to Š xref read‰  ;example 22 mainline routine Š xref initstd_‹ ; references to Š xref putnl_ ; system routines Š xref bdisplay‹ ; reference to user routine Š lds #$0ƒfŽ ; initialize S pointer ƒ  ˆ end mainline routine Š xref initstd_‹ ; references to Š xref putnl_ ; system routines Š xref bdisplay‹ ; reference to user routine Š lds #$0ƒfŽ ; initialize S pointer ƒ  end ad file control block  jsr closef_Š ;„ close file Š else” ; else  ldx #errmsgŠ ;„ load address of errmsg  jsr displayŠ ;„ display string  jsr puţlay ; display "TRUE" or "FALSE" Š jsr putnl_Ž ; skip to a new line Š swi string1ƒ rmb 41 string2ƒ rmb 41 true† fcc "TRUE" Š fcb 0 false… fcc "FALSE" Š fcb 0 length1ƒ rmb 2 Š end #„ load file control block  jsr closef_Š ;„ close file Š else” ; else  ldx #errmsgŠ ;„ load address of errmsg  jsr displayŠ ;„ display string  jsr puŒ leas 4,sŒ ;„ remove parameters from S Ž if ne ;„ if strings are equal ‘ ldx #trueˆ ;ˆ load address of "TRUE" Ž else ;„ else ‘ ldx #Œ ldx #storage† ;‡ load address  ldb ,xŒ ;‡ load chAracter into B  quif eq‹ ;‡ quit if null string  ldd outptrˆ ;‡ load file control block ‹ ead string Š ldd #string2Œ ; load address2 Š jsr length_ ; get length of string2 Š cmpd length1Œ ; compare lengths Š if eq“ ; if lengths are equal Ž pshs d† ";example 22 subroutine bdisplay Š xdef bdisplay‹ ; definition for exteded use Š xref displayŒ -; reference to user routine bdisplay lda #8’ ; load 8 into A Š loop” ; loop … † ; definition for external uses Š lds #$0ƒfŽ ; initialize S pointer Š jsr initstd_Œ ; initialize standard I/O Š ldx #string1Œ ; load address1 Š jsr read ; read string ‡ jsr initstd_Œ ; initialize standard I/O Š ldb numberŽ ; load 25 into B Š jsr bdisplayŒ ; display 25 in binary Š jsr putnl_Ž ; skip to a new line Š swi number„ fcb 25  of "1"  endif ;ƒ endif  pshs d ;ƒ save D  jsr displayŠ ;ƒ display "0" or "1"  puls d ;ƒ restore D  deca‘ ;ƒ decrement A byĘ 1  quif eqŽ ;ƒ quit if A equals 0 Š endloop‘ ; endloop Š rts char0… fcc "0" Š fcb 0 char1… fcc "1" Š fcb 0 Š end ‘ ldx #char1‡ ;… load address ;example 23 mainline routine Š xref initstd_‹ ; references to Š xref putnl_ ; system routines Š xref hdisplay‹ ; reference to user routine Š lds #$0ƒfŽ ; initialize S pointer ƒ tnl_‹ ;„ skip to a new line Š endif“ ; endif Š swi outfileƒ fcc "printer" Š fcb 0 mode† fcc "w" Š fcb 0 outptr„ rmb 2 storageƒ rmb 41 errmsg„ fcc "open error" Š fcb 0 ˆ false‡ ;ˆ load address of "FALSE" Ž endif ;„ endif Š else” ; else Ž ldx #falseŠ ;„ load address of "FALSE" Š endif“ ; endif Š jsr disp… jsr fdisplay† ;‡ diplay string  ldd outptrˆ ;‡ load file control block  jsr fputnl_‡ ;‡ skip to a new line  endloopŽ ;„ endloop  ldd outptr‹ ;ˆ ;„ push length onto S Ž ldd #string1ˆ ;„ load address1 Ž pshs dŽ ;„ push address onto S Ž ldd #string2ˆ ;„ load address2 Ž jsr equal_Š ;„ compare strings  ˆ aslb‘ ;ƒ shift B left  if cc ;ƒ if carry clear ‘ ldx #char0‡ ;… load address of "0"  else‘ ;ƒ else ‘ ldx #char1‡ ;… load address‰ ldd #string1Œ ; load address1 Š jsr length_ ; get length of string1 Š std length1 ; store length at length1 Š ldx #string2Œ ; load address2 Š jsr read ; r% ;example 15 subroutine rtn7 which ; operates from bank 7 ; and sends a message from ; another bank Š xdef rtn7 ; definition for external use Š xref getmessage‰ ; references to … ĺ"ex15" org $1ƒ0? include "disk/1.watlib.exp" "ex15m.b09" "ex12s.b09" bankorg $9ƒ0Œ ;optional banksize $1ƒ0‹ c;optional bank 1 "ex15rtn1.b09" bank 4 "ex15rtn4.b09" bank 7 "ex15rtn7.b09" bank 10 "ex15getm.b09" … ; references to …  ;example 16 mainline routine Š xref initstd_‹ ; references to Š xref putnl_ ; system routines Š xref displayŒ ; references to Š xref read ; user routines Š lds #$0ƒf‚  #storage‰ ;ƒ load address  ldb ,x ;ƒ load character into B  quif eqŽ ;ƒ quit if null string  jsr displayŠ ;ƒ display string  jsr putnl_‹ ;ƒ skip to new;example 16 subroutine read Š xdef read ; definition for exteded use Š xref getchar_‹ #; reference to system routine read† loop” ; loop  pshs x ;ƒ save X Œ ¸ Š endloop‘ ; endloop Š lda #0’ ; 0 is null byte Š sta ,x’ ; store as end-of-string Š rts Š end ‡ ; loop  pshs x ;ƒ save X Œ P‡ jsr putchar_Œ ; display character Š rts Š end „ ‰ƒ ex13s.asm‡ ‰ƒ  ex14m.asm‡ ‰ƒex14rtn1.asm„ Ë!;example 16 subroutine display Š xdef displayŒ ; definition for exteded use Š xref putchar_‹ &; reference to system routine displayƒ loop” ; loop  ldb ,x+Ž ;ƒ load character i Š rts Š end y Š xdef displayŒ ; definition for exteded use Š xref putchar_‹ &; reference to system routine displayƒ loop” ; loop  ldb ,x+Ž ;ƒ load character i!"ex16sr.b09" "ex16sd.b09" nd y Š xdef displayŒ ; definition for exteded use Š xref putchar_‹ &; reference to system routine displayƒ loop” ; loop  ldb ,x+Ž ;ƒ load character i… xref displayŒ ; user routines Š xref message1‹ ; reference to string rtn7† ldb #'7‘ ; load '7' into B Š pshs b’ ; push '7' onto S Š jsr getmessageŠ ; transfer mesJ"ex17" org $1ƒ0N include "disk/1.watlib.exp" "ex16.b09" include ex17.lib tion for exteded use Š xref putchar_‹ &; reference to system routine displayƒ loop” ; loop  ldb ,x+Ž ;ƒ load character iŒ ; initialize S pointer Š jsr initstd_Œ ; initialize standard I/O Š loop” ; loop  ldx #storage‰ ;ƒ load address  jsr read ;ƒ read string  ldx a line Š endloop‘ ; endloop Š swi storageƒ rmb 41 Š end ‰ loop” ; loop  ldx #storage‰ ;ƒ load address  jsr read ;ƒ read string  ldx  jsr getchar_‰ ;ƒ read character  puls x ;ƒ restore X  cmpb #$0dŒ ;ƒ carriage retuern?  quif eqŽ ;ƒ if yes, then quit  stb ,x+Ž ;ƒ store character;example 18 mainline routine Š xref initstd_‹ ; references to Š xref openf_ ; system routines Š xref closef_ Š xref putnl_ Š xref fputnl_ Š xref displayŒ ; references to … … xref fdisplay‹ ; definition for external uses Š xref read Š lds #$0ƒfŽ ; initialize S pointer Š jsr initstd_Œ ; initialize standard I/O Š ldd #mode ; local address of filnto B  quif eqŽ ;ƒ quit if null byte  pshs x ;ƒ save X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restore X Š endloop‘ ; endloop e mode Š pshs d’ ; push file mode onto S Š ldd #outfileŒ ; load address of filename Š jsr openf_Ž ; open file Š leas 2,s ; remove file mode from S Š std outptr Œ ; file control block address Š if ne“ ; if file opened okay  loop‘ ;„ loop  ldx #storage† ;‡ load address  jsr readŠ ;‡ read string „ Ësage Š ldx #message1‹ ; load address of message1 Š pshs x’ ; push address onto S Š jsr display ; display message Š rts Š end ‡ xref getmessage‰ ; references to …  ;example 11 subroutine Š xdef displayŒ ; definition for external use Š xref putchar_‹ &; reference to system routine displayƒ ldx 2,s‘ ; pull address into X Š loop” ; loop …  ;example 12 mainline routine Š xref initstd_‹ ; references to Š xref getchar_‹ ; system routines Š xref putnl_ Š xref displayŒ ; reference to user routine Š lds #$0ƒfŽ ; in  "hello" Š else” ; else  ldx #goodbye‰ ;ƒ load address of "goodbye" Š endif“ ; endif Š pshs x’ ; push address onto S Š jsr display ; displa ;example 12 subroutine Š xdef displayŒ ; definition for external use Š xref putchar_‹ &; reference to system routine displayƒ ldx 2,s‘ ; pull address into X Š loop” ; loop … Ę X Š endloop‘ ; endloop Š ldd ,s++ ; pull return address from S Š std ,s’ ; push in place of parameter Š rts Š end into X Š loop” ; loop … : 0 goodbyeƒ fcc "goodbye" Š fcb 0 Š end read character Š cmpb #'h Š if eq“ ; if equal to 'h'  ldd #hello‹ ;ƒ load address of "hello" Š else” ; else ˆ ‚;example 13 subroutine Š xdef displayŒ ; definition for external use Š xref putchar_‹ &; reference to system routine displayƒ ldx 2,s‘ ; pull address into X Š loop” ; loop … tialize standard I/O Š jsr getchar_Œ ; read character Š cmpb #'h Š if eq“ ; if equal to 'h'  ldd #hello‹ ;ƒ load address of "hello" Š else” ; else ˆ Ŕ X Š endloop‘ ; endloop Š leas 4,s ; remove return address & parm Š jmp [-4,s]Ž ; jump indirect through return Š end l address into X Š loop” ; loop … %;example 14 test of bank-switching Š ;mainline routine Š xref rtn1 ; references to Š xref rtn4 ; definition for external uses Š xref rtn7 Š xref bankinit_Š ; references to † ˆ ldb,x+ ; load character into B  quif eqŽ ; quit if null byte  pshs x ;ƒ store X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restoreitialize S pointer Š jsr initstd_Œ ; initialize standard I/O Š jsr getchar_Œ ; read character Š cmpb #'h Š if eq“ ; if equal to 'h'  ldx #hello‹ ;ƒ load address of Źy string Š jsr putnl_Ž ; skip to a new line Š swi hello… fcc "hello" Š fcb 0 goodbyeƒ fcc "goodbye" Š fcb 0 Š end Œ ; if equal to 'h'  ldx #hello‹ ;ƒ load address ofˆ ldb,x+ ; load character into B  quif eqŽ ; quit if null byte  pshs x ;ƒ store X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restore„ jsr rtn1 ; display '1' Š jsr putnl_Ž ; skip to a new line Š jsr rtn4 ; display '4' Š jsr putnl_Ž ; skip to a new line Š jsr rtn7 ; display '7' † M„ jsr putnl_Ž ; skip to a ne line Š swi Š end ƒ lds #$0ƒfŽ ; initialize S pointer Š jsr bankinit_‹ ; initialize bank-switching Š jsr initstd_Œ ; initialize standard I/O † ˆ ldb,x+ ; load character into B  quif eqŽ ; quit if null byte  pshs x ;ƒ store X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restore… ldd #goodbye‰ ;ƒ load address of "goodbye" Š endif“ ; endif Š jsr display ; display string Š jsr putnl_Ž ; skip to a new line Š swi hello… fcc "hello" Š fcb%;example 14 subroutine rtn1 which ;Œ operates from bank 1 Š xdef rtn1 ; definition for external use Š xref putchar_‹ ; references to system routineƒ rtn1† ldb #'1‘ ; load '1' into B ƒ „ xref initstd_‹ ; system routines Š xref putnl_ Š lds #$0ƒfŽ ; initialize S pointer Š jsr bankinit_‹ ; initialize bank-switching Š jsr initstd_Œ ; initialize standard I/O † L X Š endloop‘ ; endloop Š rts Š end xternal use Š xref putchar_‹ &; reference to system routine displayƒ ldx 2,s‘ ; pull address into X Š loop” ; loop … Š;example 1 Š lda #'a‘ ; display 'a' Š sta $8ƒ0 ; on the screen Š swi Š end ő"ex1" org $1ƒ0 "ex1.b09" 'a‘ ; display 'a' Š sta $8ƒ0 ; on the screen Š swi Š end ő Ë;example 2 Š xref putchar_‹ ; reference to system routine Š ldb #'a‘ ; display 'a' Š jsr putchar_Œ ; on the screen Š swi Š end ´7"ex2" org $1ƒ0= include "disk/1.watlib.exp" "ex2.b09" ce to system routine Š ldb #'a‘ ; display 'a' Š jsr putchar_Œ ; on the screen Š swi Š end ´ ;example 3 Š xref putchar_‹ ; reference to system routine Š ldx #string !; put address of string in X next† ldb ,x+‘ ; load character into B Š beq quit ; quit if null byte ƒ  example 3 Š xref putchar_‹ ; reference to system routine Š ldx #string !; put address of string in X next† ldb ,x+‘ ; load character into B Š beq quit ; quit if null byte ƒ ;example 4 Š xref putchar_‹ ; reference to system routine Š ldx #string ; put address of string in X Š loop” ; loop  ldb ,x+Ž ;ƒ load character into B  qCng„ fcc "hello" Š fcb $0d Š fcb 0 Š end routine Š ldx #string ; put address of string in X Š loop” ; loop  ldb ,x+Ž ;ƒ load character into B  q ;example 5 Š xref putchar_‹ ; reference to Š xref putnl_ ; system routines Š ldx #string ; put address of string in X Š loop” ; loop  ldb ,x+Ž ; ˆ ; endloop Š jsr putnl_Ž ; skip to a new line Š swi string„ fcc "hello" Š fcb 0 Š end ‡ ; put address of string in X Š loop” ; loop  ldb ,x+Ž ; ;example 6 Š xref putchar_‹ ; reference to Š xref putnl_ ; system routines Š ldx #string ; put address of string in X Š ldb ,x+‘ ; load character into B Š loop† œŠ ; until null byte in B Š jsr putnl_Ž ; skip to a new line Š swi string„ fcc "hello" Š fcb 0 Š end dress of string in X Š ldb ,x+‘ ; load character into B Š loop†  ;example 7 Š xref getchar_‹ ; reference to Š xref putchar_‹ ; system routines Š xref putnl_ Š jsr getchar_Œ ; read character Š cmpb #'h Š if eq“ ; if equal to 'h'  ldx #hello‹ ;ƒ load address of "hello" Š else” ; else  ldx #goodbye‰ ;ƒ load address of "goodbye" Š endif“ ; endif Š loop” ; loop ‡ pshs x’ ; save X Š jsr putchar_Œ ; display character Š puls x’ ; restore X Š bra next ; repeat loop quit† swi string„ fcc "hello" Š fcb 0 Š end‚Œ ldb,x+ ; load character into B  quif eqŽ ; quit if null byte  pshs x ;ƒ store X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ resuif eqŽ ;ƒ quit if null byte  pshs x ;ƒ save X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restore X Š endloop‘ ; endloop Š swi stri Ötore X Š endloop‘ ; endloop Š jsr putnl_Ž ; skip to a new line Š swi hello… fcc "hello" Š fcb 0 goodbyeƒ fcc "goodbye" Š fcb 0 Š end ‰ loop” ; loop  load character into B  quif eqŽ ;ƒ quit if null byte  pshs x ;ƒ save X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restore X Š endloop‰ ;example 8 mainline routine Š xref initstd_‹ ; references to Š xref getchar_‹ ; system routines Š xref putnl_ Š xref displayŒ ; reference to user routine Š jsr initstd_Œ ; ini Ž ; loop  pshs x ;ƒ save X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restore X  ldb,x+ ;ƒ load character into B Š until eq† 8A˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˘Š  hې5ß˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙ ‘ ‚  2A„ Ő ex1.asm‰ ‰ƒ ex1.cmd‰ ‰ƒ ex2.asm‰ ‰ƒ ex2.cmd‰ ‰ƒ ex3.asm‰ ‰ƒ ex4.asm‰ ‰ƒ ex5.asm‰ ‰ƒ  ex6.asm‰ ‰˙ex25m.asm‡ ‰ƒ  ex26m.asm‡ ‰ ˙Â˙˙‚  ex7.asm‰ ‰ƒ ex8m.asmˆ ‰ƒ ex8s.asmˆ ‰ƒ ex8.cmd‰ ‰ƒ ex9m.asmˆ ‰ƒ ex9s.asmˆ ‰ƒ ex10m.asm‡ ‰ƒ  ex11m.asm‡ ‰˙˙‚˙˙‚ ex11s.asm‡ ‰ƒ ex12m.asm‡ ‰ƒ ex12s.asm‡ ‰ƒ ex13s.asm‡ ‰ƒ  ex14m.asm‡ ‰ƒex14rtn1.asm„ ‰ƒex14rtn4.asm„ ‰ƒex14rtn7.asm„ ‰˙˙‚˙˙‚  ex14.cmdˆ ‰ƒ ex15m.asm‡ ‰ƒex15getm.asm„ ‰ƒex15rtn1.asm„ ‰ƒ ex15rtn4.asm„ ‰ƒex15rtn7.asm„ ‰ƒ ex15.cmdˆ ‰ƒ ex16.asmˆ ‰˙˙‚˙˙‚ex16sr.asm† ‰ƒ ex16sd.asm† ‰ƒ  ex17.libˆ ‰ƒ  ex17.cmdˆ ‰ƒ ex18m.asm‡ ‰ ƒ ex18sf.asm† ‰ƒ ex.libŠ ‰ƒ ex18.cmdˆ ‰˙˙‚˙˙‚ex19m.asm‡ ‰ ƒ  ex20m.asm‡ ‰ƒ ex21m.asm‡ ‰ƒ ex22m.asm‡ ‰ƒ  ex22sb.asm† ‰ƒ ex23m.asm‡ ‰ƒ ex23sh.asm† ‰ƒ ex24m.asm‡ ‰˙˙‚˙˙‚ ;example 8 subroutine Š xdef displayŒ ; definition for external use Š xref putchar_‹ &; reference to system routine displayƒ tfr d,x‘ ; transfer D to X Š loop” ; loop Š Gˆ endloop‘ ; endloop Š rts Š end or external use Š xref putchar_‹ &; reference to system routine displayƒ tfr d,x‘ ; transfer D to X Š loop” ; loop Š C"ex8" org $1ƒ0G include "disk/1.watlib.exp" "ex8m.b09" "ex8s.b09" end or external use Š xref putchar_‹ &; reference to system routine displayƒ tfr d,x‘ ; transfer D to X Š loop” ; loop Š  ;example 9 mainline routine Š xref initstd_‹ ; references to Š xref getchar_‹ ; system routines Š xref putnl_ Š xref displayŒ ; reference to user routine Š jsr initstd_Œ ; ini… ldx #goodbye‰ ;ƒ load address of "goodbye" Š endif“ ; endif Š pshs x’ ; push address onto S Š jsr display ; display string Š jsr putnl_Ž ; skip to a new;example 9 subroutine Š xdef displayŒ ; definition for external use Š xref putchar_‹ &; reference to system routine displayƒ puls y’ ; pull return address into Y Š puls x’ ; pullÍx ;ƒ store X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restore X Š endloop‘ ; endloop Š rts Š end ss into Y Š puls x’ ; pull ;example 10 mainline routine Š xref initstd_‹ ; references to Š xref getchar_‹ ; system routines Š xref putnl_ Š xref displayŒ ; reference to user routine Š lds #$0ƒfŽ ; i f "hello" Š else” ; else  ldx #goodbye‰ ;ƒ load address of "goodbye" Š endif“ ; endif Š pshs x’ ; push address onto S Š jsr display ; displ ;example 11 mainline routine Š xref initstd_‹ ; references to Š xref getchar_‹ ; system routines Š xref putnl_ Š xref displayŒ ; reference to user routine Š lds #$0ƒfŽ ; inƒ ldb,x+ ; load character into B  quif eqŽ ; quit if null byte  pshs x ;ƒ store X  jsr putchar_‰ ;ƒ display character  puls x ;ƒ restore X  itialize S pointer Š jsr initstd_Œ ; initialize standard I/O Š jsr getchar_Œ ; read character Š cmpb #'h Š if eq“ ; if equal to 'h'  ldx #hello‹ ;ƒ load address of  "hello" Š else” ; else  ldx #goodbye‰ ;ƒ load address of "goodbye" Š endif“ ; endif Š pshs x’ ; push address onto S Š jsr display ; displatialize standard I/O Š jsr getchar_Œ ; read character Š cmpb #'h Š if eq“ ; if equal to 'h'  ldx #hello‹ ;ƒ load address of "hello" Š else” ; else ˆ r line Š swi hello… fcc "hello" Š fcb 0 goodbyeƒ fcc "goodbye" Š fcb 0 Š end Œ ; if equal to 'h'  ldx #hello‹ ;ƒ load address of "hello" Š else” ; else ˆ  string address into X Š pshs y’ ; push return back onto S Š loop” ; loop  ldb,x+ ; load character into B  quif eqŽ ; quit if null byte  pshs ćy string Š leas 2,s ; remove address from S Š jsr putnl_Ž ; skip to a new line Š swi hello… fcc "hello" Š fcb 0 goodbyeƒ fcc "goodbye" Š fcb 0 Š end † ;ƒ load address ofnitialize S pointer Š jsr initstd_Œ ; initialize standard I/O Š jsr getchar_Œ ; read character Š cmpb #'h Š if eq“ ; if equal to 'h'  ldx #hello‹ ;ƒ load address o ­ay string Š jsr putnl_Ž ; skip to a new line Š swi hello… fcc "hello" Š fcb 0 goodbyeƒ fcc "goodbye" Š fcb 0 Š end Œ ; if equal to 'h'  ldx #hello‹ ;ƒ load address o% ;example 14 subroutine rtn4 which ;Œ operates from bank 4 Š xdef rtn4 ; definition for external use Š xref putchar_‹ $; references to system routine rtn4† ldb #'4‘ ; load '4' into B „ % ;example 14 subroutine rtn7 which ;Œ operates from bank 7 Š xdef rtn7 ; definition for external use Š xref putchar_‹ $; references to system routine rtn7† ldb #'7‘ ; load '7' into B „ Â"ex14" org $1ƒ03 include "disk/1.watlib.exp" "ex14m.b09" bankorg $9ƒ0Œ ;optional banksize $1ƒ0‹ Z;optional bank 0 "ex14rtn1.b09" bank 4 "ex14rtn4.b09" bank 7 "ex14rtn7.b09" ex14rtn4.asm„ ‰ƒex14rtn7.asm„ ‰& ;example 15 test of bank-switching ; &with data in a bank ;mainline routine Š xdef message1‹ ; external use of string Š xref rtn1 ; references to Š xref rtn4 ; definition for externae bank-switching Š jsr initstd_Œ ; initialize standard I/O Š jsr rtn1 ; display "hello ƒ. 1" Š jsr putnl_Ž ; skip to a new line Š jsr rtn4 ; display "hello ƒ. 4" † $;example 15 subroutine to handle ; data in bank switched ; memory  xdef getmessage‰ ; definition for external use  xref message1‹ '; reference to system label getmessage† lda 2” ; transfer string “ lda,x+ ;„ "hello from bank x" “ quif eqŽ ;„ from message to “ sta,y+ ;„ message1 in the  endloop† &‹ fcb 0  end “ lda,x+ ;„ "hello from bank x" “ quif eqŽ ;„ from message to “ sta,y+ ;„ message1 in the  endloop† %;example 15 subroutine rtn1 which ; operates from bank 1 ; and sends a message from ; another bank Š xdef rtn1 ; definition for external use Š xref getmessage‰ ; references to … Ësage Š ldx #message1‹ ; load address of message1 Š pshs x’ ; push address onto S Š jsr display ; display message Š rts Š end ‡ xref getmessage‰ ; references to … O† jsr putchar_Œ ; display character Š rts Š end … ‰ƒ ex13s.asm‡ ‰ƒ  ex14m.asm‡ ‰ƒex14rtn1.asm„ ‰ƒex14rtn4.asm„ ŤO† jsr putchar_Œ ; display character Š rts Š end … ‰ƒ ex13s.asm‡ ‰ƒ  ex14m.asm‡ ‰ƒex14rtn1.asm„ ‰ƒex14rtn4.asm„ ‰ƒex14rtn7.asm„ ‹%;example 15 subroutine rtn4 which ; operates from bank 4 ; and sends a message from ; another bank Š xdef rtn4 ; definition for external use Š xref getmessage‰ ; references to … l uses Š xref rtn7 Š xref bankinit_Š ; references to Š xref initstd_‹ ; system routines Š xref putnl_ Š lds #$0ƒfŽ ; initialize S pointer Š jsr bankinit_‹ ; initializ℠jsr putnl_Ž ; skip to a new line Š jsr rtn7 ; display "hello ƒ. 7" Š jsr putnl_Ž ; skip to a new line Š swiƒ message1 rmb 17 Š fcb 0 Š end nkinit_‹ ; initializ,s‘ ; load character into A  sta numberŽ ; store character  ldx #messageŒ ; load address of message  ldy #message1‹ ; load address of message1  loop‹ ; mainline routine  ldd ,s+‘ ; load return address &  std ,s’ ; store in place of parameter  rtsƒ message‰ fcc "hello from bank " numberŠ fcc "x" … … xref displayŒ ; user routines Š xref message1‹ ; reference to string rtn4† ldb #'4‘ ; load '4' into B Š pshs b’ ; push 'B' onto S Š jsr getmessageŠ ; transfer mes … xref displayŒ ; user routines Š xref message1‹ ; reference to string rtn1† ldb #'1‘ ; load '1' into B Š pshs b’ ; push '1' onto S Š jsr getmessageŠ ; transfer mes" ;example 18 subroutine fdisplay Š xdef fdisplay‹ ; definition for exteded use Š xref fputchar_Š 4; reference to system routine fdisplay std outptr Š loop” ; loop  ldb ,x+Œ ýŠ jsr fputchar_ˆ ;ƒ display character  leas 2,s ;ƒ remove parameter from S  puls x ;ƒ restore X Š endloop‘ ; endloop Š rts outptr„ rmb 2 Š end 7("ex16sr.b09" "ex16sd.b09" "ex18sf.b09" lay character  leas 2,s ;ƒ remove parameter from S  puls x ;ƒ restore X Š endloop‘ ; endloop Š rts outptr„ rmb 2 Š end I"ex18" org $1ƒ0: include "disk/1.watlib.exp" "ex18m.b09" include ex.lib ,s ;ƒ remove parameter from S  puls x ;ƒ restore X Š endloop‘ ; endloop Š rts outptr„ rmb 2 Š end ;example 19 mainline routine Š xref initstd_‹ ; references to Š xref openf_ ; system routines Š xref closef_ Š xref putnl_ Š xref fputnl_ Š xref displayŒ ; references to … e mode Š pshs d’ ; push file mode onto S Š ldd #outfileŒ ; load address of filename Š jsr openf_Ž ; open file Š leas 2,s ; remove file mode from S Š std outptr Œ ldx #storage† ;‡ load address  ldb ,xŒ ;‡ load character into B  quif eq‹ ;‡ quit if null string  ldd outptrˆ ;‡ load file control block ‹ Ësage Š ldx #message1‹ ; load address of message1 Š pshs x’ ; push address onto S Š jsr display ; display message Š rts Š end ‡ xref getmessage‰ ; references to … ƒ load file control block  jsr closef_Š ;„ close file Š else” ; else  ldx #errmsgŠ ;„ load address of errmsg  jsr displayŠ ;„ display string  jsr put end d file control block  jsr closef_Š ;„ close file Š else” ; else  ldx #errmsgŠ ;„ load address of errmsg  jsr displayŠ ;„ display string  jsr put ;ƒ load character into B  quif eqŽ ;ƒ quit if null byte  pshs x ;ƒ save X  pshs d ;ƒ push character onto S  ldd outptr‹ ;ƒ load file control block ƒ  ;example 20 mainline routine Š xref initstd_‹ ; references to Š xref putnl_ ; system routines Š xref streq_ Š xref displayŒ ; references to Š xref read ; definition for  external uses Š lds #$0ƒfŽ ; initialize S pointer Š jsr initstd_Œ ; initialize standard I/O Š ldx #string1Œ ; load address1 Š jsr read ; read string Š ldx #string2 Š ; load address2 Š jsr read ; read string Š ldd #string2Œ ; load address2 Š pshs d’ ; push address onto S Š ldd #string1Œ ; load address1 Š jsr streq_„ … xref fdisplay‹ ; definition for external uses Š xref read Š lds #$0ƒfŽ ; initialize S pointer Š jsr initstd_Œ ; initialize standard I/O Š ldd #mode ; local address of filŒ ; file control block address Š if ne“ ; if file opened okay  loop‘ ;„ loop  ldx #storage† ;‡ load address  jsr readŠ ;‡ read string „ … jsr fdisplay† ;‡ write string  ldd outptrˆ ;‡ load file control block  jsr fputnl_‡ ;‡ skip to a new line  endloopŽ ;„ endloop  ldd outptr‹ ; Š ; compare to strings Š leas 2,s ; remove string2 address from S Š if ne“ ; if string are equal Ž ldx #true‹ ;„ load address of "TRUE" Š else” ; els nl_‹ ;„ skip to a new line Š endif“ ; endif Š swi outfileƒ fcc "tempfile" Š fcb 0 mode† fcc "w" Š fcb 0 outptr„ rmb 2 storageƒ rmb 41 errmsg„ fcc "open error" Š fcb 0 ˆ " ;example 23 subroutine hdisplay Š xdef hdisplay‹ ; definition for exteded use Š xref putchar_‹ +; reference to user routine hdisplay clra” ; clear A Š pshs d’ ; save D ‰  ransfer D to X Š ldb hchars,xŒ ; load hex digit into B Š jsr putchar_Œ ; display first hex char Š puls d’ ; restore D Š andb #$0f ; value of second hex digit Š tfr  ;example 24 mainline routine Š xref initstd_ ; references to Š xref printf_ ; system routines Š jsr initstd_ ; initialize standard I/O Š ldb char1“ ; load 'a' i • ; push 25 onto S Š ldd #string2 ; load address2 Š jsr printf_‘ ; display string2 formatted Š ldd #string‘ ; load address Š pshs d– ; pusƒ swi string1ƒ 0fcc "printf_ can be used to display characters" Š fcc " such as %c.%n" Š fcb 0 string2ƒ .fcc "it can also be used to display decimal " Š fcc "numbers such as %d.%n" Š fcb 0 string3ƒ fcc "or hexadecimal n˝ ; and %h in string3 string„ /fcc "'This is a string.'" ; substitution value ­ ; for %s in string3 Š fcb 0 Š end ers such as %d.%n" Š fcb 0 string3ƒ fcc "or hexadecimal n;example 25 mainline routine Š xref initstd_‹ ; references to Š xref putchar_‹ ; system routines Š xref putnl_ Š xref itos_ Š xref displayŒ #; reference to user routine prints„ macr e Ž ldx #falseŠ ;„ load address of "FALSE" Š endif“ ; endif Š jsr display ; display "TRUE" or "FALSE" Š jsr putnl_Ž ; skip to a new line Š swi string1ƒ rmb 4Š ldb #'‹ ;† load ' ' into B ‘ pshs y‹ ;† save Y ‘ jsr putchar_… ;† display blank ‘ puls y‹ ;† restore Y ‘ leay -1,yˆ ;† decrementro "prints" Š jsr initstd_Œ ; initialize standard I/O Š jsr putnl_Ž ; skip to a new line Š ldx #leftstrŒ ; load address of leftstr Š ldb #'1‘ ; on left side Š prints  lsrb” ; shift B right 4 times Š lsrb” ; in order to have D Š lsrb” ; contain value of Š lsrb” ; first hexadecimal digit Š tfr d,x‘ ; tŰd,x‘ ; transfer D to X Š ldb hchars,xŒ ; load hex digit into B Š jsr putchar_Œ ; display second hex char Š rts hchars„ fcc "0123456789ABCDEF" Š end ‰ tfr d,x‘ ; tnto B Š pshs d– ; push 'a' onto S Š ldd #string1 ; load address1 Š jsr printf_‘ ; display string1 formatted Š ldd number’ ; load 25 into D Š pshs d h address onto S Š ldd number’ ; load 25 into D Š pshs d– ; push 25 onto S Š ldd #string3 ; load address3 Š jsr printf_‘ ; display string3 formatted ‡ umbers such as %h or " Š fcc "strings such as %ss.%n" Š fcb 0 char1… fcb 'a– -; substitution value for %c in string1 number„ fdb 25– '; substitution value for %d in string2 – ‘ ; display "ODD" Š ldx #rightstr‹ ; load address of rightstr Š ldb #'r‘ ; on right side Š prints’ ; display "EVEN" Š jsr putnl_Ž ; skip to a new line „ ˆ cmpb #'r ; compare B to 'r' Š if eq“ ; if B equals 'r' Ž ldy #40 ;„ load Y with 40 Ž pshs xŽ ;„ save X Ž loop ;„ loop ‡ m1 string2ƒ rmb 41 true† fcc "TRUE" Š fcb 0 false… fcc "FALSE" Š fcb 0 Š end f ne“ ; if string are equal Ž ldx #true‹ ;„ load address of "TRUE" Š else” ; els  Y by 1 Ž until eqŒ ;„ quit if Y equals 0 Ž puls xŽ ;„ restore X Š endif“ ; endif Š jsr display ; display string Š endm” ; end of mac˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚“† swi leftstrƒ fcc "ODD" Š fcb 0 rightstr fcb 8 Š fcb 8 Š fcb 8 Š fcc "EVEN" Š fcb 0 Š end tstrŒ ; load address of leftstr Š ldb #'1‘ ; on left side Š prints ˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚˙˙‚