10 brkv=&202 20 osasci=&FFE3 30 osbyte=&FFF4 40 oscli=&FFF7 50 osfile=&FFDD 60 osnewl=&FFE7 70 osrdch=&FFE0 80 osword=&FFF1 90 oswrch=&FFEE 100 last=&74FF 110 screenst=&7C00 120 block=&100 130 lines=&19 140 length=&28 150 textstart=&70 160 textend=&72 170 mempos=&74 180 textptrs=&75 190 temp=&76 200 gtext=&78 210 hpos=&7C 220 vpos=&7D 230 curpos=&7E 240 retaddr=&FD 250 PROCASM(0) 260 PROCASM(0) 270 PROCASM(3) 280 PRINT "CALL &7500 to run" 290 END 300 310 DEF PROCASM(opt%) 320 P%=&7500 330 [ OPT opt% 340 LDA #&04 ;Make cursor keys return ASCII codes 350 LDX #&01 360 JSR osbyte 370 LDA #break MOD 256 ;Point BRK vector to new BRK handler 380 STA brkv 390 LDA #break DIV 256 400 STA brkv+1 410 LDA #&83 ;Calculate 0S high water mark (OSHWM) 420 JSR osbyte 430 STX textstart ;and store it in textstart and textend 440 STY textstart+1 450 STX textend 460 STY textend+1 470 .textptrs LDA textstart ;Define curpos and mempos 480 STA curpos 490 STA mempos 500 LDA textstart+1 510 STA curpos+1 520 STA mempos+1 530 LDA #&00 ;Set cursor to top left 540 STA hpos 550 STA vpos 560 .menu LDA #&16 ;Select MODE 7 for screen mode 570 JSR oswrch 580 LDA #&07 590 JSR oswrch 600 LDX #&07 ;7 lines to be printed 610 LDY #&00 ;Start count at zero 620 .mloop LDA mtext,Y 630 JSR osasci ;Print menu 640 INY 650 CMP #&0D ;End of a menu item? 660 BNE mloop ;No, get remaining letters 670 DEX ;Update counter 680 BNE mloop 690 .mloop2 JSR osrdch ;Input a character from keyboard 700 BCC mnoerr ;Check if ESCAPE was pressed 710 CMP #&1B 720 BNE mnoerr 730 LDA #&7E ;Acknowledge ESCAPE condition 740 JSR osbyte 750 JMP mloop2 ;and try again 760 .mnoerr CMP #ASC("*") ;Validate input (1-4 or %) 770 BEQ mcase 780 CMP #ASC("1") 790 BCC mloop2 800 CMP #ASC("5") 810 BCS mloop2 820 .mcase CMP #ASC("1") ;Case A of ... 830 BNE mnotload 840 JMP load 850 .mnotload CMP #ASC("2") 860 BNE mnotsave 870 JMP save 880 .mnotsave CMP #ASC("3") 890 BNE mnotedit 900 JMP edit 910 .mnotedit CMP #ASC("4") 920 BNE mnotprint 930 JMP print 940 .mnotprint JMP oscom 950 .mtext EQUS " " 960 EQUS "WORDPRO" 970 EQUB &0D 980 EQUB &0D 990 EQUS "1. Load a file" 1000 EQUB &0D 1010 EQUS "2. Save a file" 1020 EQUB &0D 1030 EQUS "3. Edit a file" 1040 EQUB &0D 1050 EQUS "4. Print a file" 1060 EQUB &0D 1070 EQUS "*. OS command" 1080 EQUB &0D 1090 .load JSR osnewl ;Output a carriage return 1100 LDX #&00 ;Prompt user for input 1110 .lloop LDA ltext,X 1120 CMP #&0D 1130 BEQ lout 1140 JSR osasci 1150 INX 1160 JMP lloop 1170 .lout LDA #&0C ;Input parameter ~ max. line length 1180 JSR input 1190 BCC lover 1200 JMP menu 1210 .lover LDA #buffer MOD 256 ;Set up a block for loading 1220 STA block ;Block 0-1 address of filename 1230 LDA #buffer DIV 256 1240 STA block+1 1250 LDA textstart ;Block 2-5 load address 1260 STA block+2 1270 LDA textstart+1 1280 STA block+3 1290 LDA #&00 1300 STA block+4 1310 STA block+5 1320 STA block+6 ;Block 6 load address flag 1330 LDA #&FF ;OSFILE command (load file) 1340 LDX #block MOD 256 1350 LDY #block DIV 256 1360 JSR osfile 1370 LDA block+10 ;Calculate new textend 1380 CLC 1390 ADC textstart 1400 STA textend 1410 LDA block+11 1420 ADC textstart+1 1430 STA textend+1 1440 JMP textptrs 1450 .ltext EQUS "File to load: " 1460 EQUB &0D 1470 .save JSR osnewl ;Output a carriage return 1480 LDX #&00 ;Prompt user for input 1490 .sloop LDA stext,X 1500 CMP #&0D 1510 BEQ sout 1520 JSR osasci 1530 INX 1540 JMP sloop 1550 .sout LDA #&0C ;Input parameter - max. line length 1560 JSR input 1570 BCC sover 1580 JMP menu 1590 .sover LDA #buffer MOD 256 ;Set up a block for saving 1600 STA block ;Block 0-1 address of filename 1610 LDA #buffer DIV 256 1620 STA block+1 1630 LDA #&00 ;Block 2-5 load address 1640 STA block+2 1650 STA block+3 1660 STA block+4 1670 STA block+5 1680 STA block+6 ;Block 6-9 execution address 1690 STA block+7 1700 STA block+8 1710 STA block+9 1720 LDA textstart ;Block 10-13 start of data to save 1730 STA block+10 1740 LDA textstart+1 1750 STA block+11 1760 LDA #&00 1770 STA block+12 1780 STA block+13 1790 LDA textend ;Block 14-17 byte after end of data 1800 STA block+14 1810 LDA textend+1 1820 STA block+15 1830 LDA #&00 1840 STA block+16 1850 STA block+17 1860 LDA #&00 ;OSFILE command (save file) 1870 LDX #block MOD 256 1880 LDY #block DIV 256 1890 JSR osfile 1900 JMP menu 1910 .stext EQUS "Save as: " 1920 EQUB &0D 1930 .edit LDA #&FF ;Mark textend with rogue value &FF 1940 LDY #&00 1950 STA (textend),Y 1960 .estart JSR display 1970 LDA #&1F ;Display cursor 1980 JSR oswrch 1990 LDA hpos 2000 JSR oswrch 2010 LDA vpos 2020 JSR oswrch 2030 JSR osrdch ;Input a character from keyboard 2040 CMP #&88 ;Case A of ... 2050 BNE enotleft 2060 JSR cleft 2070 JMP estart 2080 .enotleft CMP #&89 2090 BNE enotright 2100 JSR cright 2110 JMP estart 2120 .enotright CMP #&8A 2130 BNE enotdown 2140 JSR cdown 2150 JMP estart 2160 .enotdown CMP #&8B 2170 BNE enotup 2180 JSR cup 2190 JMP estart 2200 .enotup CMP #&7F 2210 BNE enotrub 2220 JSR rubout 2230 JMP estart 2240 .enotrub CMP #&0D 2250 BEQ eover 2260 CMP #&20 2270 BCC enotwrite 2280 CMP #&7F 2290 BCS enotwrite 2300 .eover JSR write 2310 JMP estart 2320 .enotwrite CMP #&1B 2330 BNE enoerr 2340 LDA #&7E ;Acknowledge ESCAPE condition 2350 JSR osbyte 2360 JMP menu 2370 .enoerr JMP estart 2380 .print LDA #&0C ;Clear the screen 2390 JSR oswrch 2400 LDA #&02 ;Turn the printer on 2410 JSR oswrch 2420 LDA textstart ;Set up text pointers 2430 STA temp 2440 LDA textstart+1 2450 STA temp+1 2460 LDA textend 2470 STA temp+2 2480 LDA textend+1 2490 STA temp+3 2500 LDY #&00 2510 .ploop TXA ;Store registers 2520 PHA 2530 TYA 2540 PHA 2550 LDA #&79 ;Check if ESCAPE is being pressed 2560 LDX #&F0 2570 JSR osbyte 2580 CPX #&00 2590 BPL pok 2600 LDA #&03 ;It is, so turn the printer off 2610 JSR oswrch 2620 LDA #&15 ;and flush the printer buffer 2630 LDX #&03 2640 JSR osbyte 2650 PLA ;Clean up the stack 2660 PLA 2670 JMP menu 2680 .pok PLA ;Retrieve registers 2690 TAY 2700 PLA 2710 TAX 2720 LDA temp ;Have we reached textend? 2730 CMP temp+2 2740 BNE pover 2750 LDA temp+1 2760 CMP temp+3 2770 BEQ pout ;Yes, so return 2780 .pover LDA (temp),Y 2790 JSR osasci ;Print the character 2800 INC temp ;Move to next character 2810 BNE pnoinc 2820 INC temp+1 2830 .pnoinc JMP ploop 2840 .pout LDA #&03 ;Turn the printer off 2850 JSR oswrch 2860 JSR osnewl 2870 JSR getkey ;Wait for a key press 2880 JMP menu 2890 .oscom JSR osnewl ;Output a carriage return 2900 LDA #ASC("*") ;and an asterisk as a prompt 2910 JSR osasci 2920 LDA #&FF ;Input parameter - max. line length 2930 JSR input 2940 LDX #buffer MOD 256 ;OSCLI command 2950 LDY #buffer DIV 256 2960 JSR oscli 2970 JSR osnewl 2980 JSR getkey ;Wait for a key press 2990 JMP menu 3000 .input PHA ;Save parameter on the stack 3010 LDA #buffer MOD 256 ;Set up a block for input 3020 STA block ;Block 0-1 address of buffer 3030 LDA #buffer DIV 256 3040 STA block+1 3050 PLA ;Block 2 maximum line length 3060 STA block+2 3070 LDA #ASC(" ") ;Block 3 min. acceptable ASCII value 3080 STA block+3 3090 LDA #&7F ;Block 4 max. acceptable ASCII value 3100 STA block+4 3110 LDA #&00 ;OSWORD command (input string) 3120 LDX #block MOD 256 3130 LDY #block DIV 256 3140 JSR osword 3150 BCC iout ;Check if ESCAPE was pressed 3160 LDA #&7E ;Acknowledge ESCAPE condition 3170 JSR osbyte 3180 JMP menu 3190 .iout RTS 3200 .getkey LDX #&00 3210 .gloop LDA gtext,X ;Prompt user for a key press 3220 BEQ gout 3230 JSR osasci 3240 INX 3250 JMP gloop 3260 .gout JSR osrdch ;Wait for a key press 3270 BCC gout2 ;Check if ESCAPE was pressed 3280 CMP #&1B 3290 BNE gout2 3300 LDA #&7E ;Acknowledge ESCAPE condition 3310 JSR osbyte 3320 .gout2 RTS 3330 .gtext EQUS "Press any key." 3340 EQUB &00 3350 .break JSR osnewl ;Output a carriage return 3360 LDY #&01 ;Output error message 3370 .bloop LDA (retaddr),Y 3380 BEQ bout 3390 INY 3400 JSR osasci 3410 JMP bloop 3420 .bout LDA #ASC(" ") ;Output a dash 3430 JSR osasci 3440 LDA #ASC("-") 3450 JSR osasci 3460 LDA #ASC(" ") 3470 JSR osasci 3480 JSR getkey ;Wait for a key press 3490 PLA ;Discard unwanted return address 3500 PLA 3510 PLA ;and status register 3520 JMP menu 3530 .display LDA mempos ;Start displaying from mempos 3540 STA temp 3550 LDA mempos+1 3560 STA temp+1 3570 LDA #&00 ;Set end of text flag to false 3580 STA temp+2 3590 LDA #lines ;Set line count to lines 3600 STA temp+3 3610 LDA #screenst MOD 256 ;Define screen pointer 3620 STA temp+4 3630 LDA #screenst DIV 256 3640 STA temp+5 3650 LDY #&00 3660 .dloop LDX #length ;Set row count to length 3670 .dloop2 LDA (temp),Y ;Get character from text 3680 CMP #&FF ;Text finished? (&FF is a rogue value) 3690 BNE dnotend 3700 STA temp+2 ;Yes, so set end of text flag to true 3710 JMP dspaces 3720 .dnotend CMP #&0D ;Is there a carriage return in text? 3730 BEQ dspaces 3740 BIT temp+2 ;Is the end of text flag set? 3750 BEQ dover ;No, so skip dspaces 3760 .dspaces LDA #ASC(" ") ;Print spaces to end of line 3770 .dsloop STA (temp+4),Y 3780 INC temp+4 ;Update counters 3790 BNE dsnoinc 3800 INC temp+5 3810 .dsnoinc DEX 3820 BNE dsloop 3830 JMP dout 3840 .dover STA (temp+4),Y ;Print current character 3850 DEX ;Update counters 3860 INC temp+4 3870 BNE dout 3880 INC temp+5 3890 .dout INC temp 3900 BNE dnoinc 3910 INC temp+1 3920 .dnoinc CPX #&00 ;Have we printed a whole line yet? 3930 BNE dloop2 ;No, so do next character 3940 DEC temp+3 ;Have we finished yet? 3950 BNE dloop ;No, so do next line 3960 RTS 3970 .cleft LDA curpos ;Are we at textstart? 3980 CMP textstart 3990 BNE clok 4000 LDA curpos+1 4010 CMP textstart+1 4020 BNE clok 4030 RTS ;Yes, so return 4040 .clok LDA curpos ;Decrement curpos 4050 SEC 4060 SBC #&01 4070 STA curpos 4080 LDA curpos+1 4090 SBC #&00 4100 STA curpos+1 4110 LDA hpos ;Are we in the top left hand corner? 4120 BNE clover2 4130 LDA vpos 4140 CMP #&00 4150 BNE clover 4160 JSR sdown ;Yes, so scroll down 4170 JMP clover2 4180 .clover DEC vpos ;Decrement vpos 4190 .clover2 LDY #&00 ;Is there a carriage return at curpos? 4200 LDA (curpos),Y 4210 CMP #&0D 4220 BNE clnocr 4230 JSR nlcalc ;Yes, so get correct value for hpos 4240 STA hpos 4250 RTS 4260 .clnocr LDA hpos ;Are we in the leftmost column? 4270 BEQ clover3 4280 DEC hpos ;No, so decrement hpos 4290 RTS 4300 .clover3 LDA #length-1 ;Set hpos to far right 4310 STA hpos 4320 RTS 4330 .cright LDY #&00 ;Are we at the end of text? 4340 LDA (curpos),Y 4350 CMP #&FF 4360 BNE crok 4370 RTS ;Yes, so return 4380 .crok INC curpos ;Increment curpos 4390 BNE crnoinc 4400 INC curpos+1 4410 .crnoinc CMP #&0D ;Is there a carriage return at curpos? 4420 BNE crnocr 4430 LDA #&00 ;Yes, so set hpos to far left 4440 STA hpos 4450 JMP crscroll ;Scroll up if necessary 4460 .crnocr LDA hpos ;Are we in the rightmost column? 4470 CMP #length-1 4480 BEQ crover2 4490 INC hpos ;No, so increment hpos 4500 RTS 4510 .crover2 LDA #&00 ;Set hpos to far left 4520 STA hpos 4530 .crscroll LDA vpos ;Are we on the bottom line? 4540 CMP #lines-1 4550 BNE crover3 4560 JSR sup ;Yes, so scroll up 4570 RTS 4580 .crover3 INC vpos ;Increment vpos 4590 RTS 4600 .cdown LDA #length ;Set limit to length-hpos 4610 SEC 4620 SBC hpos 4630 STA temp 4640 LDY #&00 ;Set count to zero 4650 .cdloop LDA (curpos),Y ;Is there a carriage return at curpos? 4660 CMP #&0D 4670 BEQ cdout2 ;Yes, so exit loop 4680 CMP #&FF ;Have we reached textend? 4690 BEQ cdout ;Yes, so return 4700 INY ;Update counter 4710 CPY temp ;Has count reached limit? 4720 BEQ cdout2 ;Yes, so exit both loops 4730 JMP cdloop 4740 .cdout RTS 4750 .cdout2 LDA vpos ;Are we on the bottom line? 4760 CMP #lines-1 4770 BNE cdover 4780 JSR sup ;Yes, so scroll up 4790 JMP cdover2 4800 .cdover INC vpos ;Increment vpos 4810 .cdover2 LDA #length ;Set count to length-hpos 4820 SEC 4830 SBC hpos 4840 TAX 4850 LDY #&00 4860 .cdloop2 LDA (curpos),Y ;Is there a carriage return at curpos? 4870 CMP #&0D 4880 BEQ cdout3 ;Yes, so exit loop 4890 INC curpos ;Increment curpos 4900 BNE cdnoinc 4910 INC curpos+1 4920 .cdnoinc DEX ;Update counter 4930 BEQ cdloop3 ;and exit loop if finished 4940 JMP cdloop2 4950 .cdout3 LDX #&00 ;Set count to zero 4960 INC curpos ;and increment curpos 4970 BNE cdloop3 4980 INC curpos+1 4990 .cdloop3 CPX hpos ;Has count reached hpos? 5000 BEQ cdout5 ;Yes, so exit loop 5010 LDA (curpos),Y ;Is there a carriage return at curpos? 5020 CMP #&0D 5030 BEQ cdout4 ;Yes, so exit loop 5040 CMP #&FF ;Have we reached textend? 5050 BEQ cdout4 ;Yes, so exit loop 5060 INC curpos ;Increment curpos 5070 BNE cdnoinc2 5080 INC curpos+1 5090 .cdnoinc2 INX ;Update counter 5100 JMP cdloop3 5110 .cdout4 STX hpos ;Set hpos to count 5120 .cdout5 RTS 5130 .cup LDA mempos ;Are we on the top line? 5140 CMP textstart 5150 BNE cuok 5160 LDA mempos+1 5170 CMP textstart+1 5180 BNE cuok 5190 LDA vpos 5200 BNE cuok 5210 RTS ;Yes, so return 5220 .cuok LDX #length ;Set count to length 5230 LDY #&00 5240 .culoop LDA curpos ;Decrement curpos 5250 SEC 5260 SBC #&01 5270 STA curpos 5280 LDA curpos+1 5290 SBC #&00 5300 STA curpos+1 5310 DEX ;Update counter 5320 BEQ cunocr ;and exit loop if finished 5330 LDA (curpos),Y ;Is there a carriage return at curpos? 5340 CMP #&0D 5350 BNE culoop ;No, so loop back 5360 JSR nlcalc ;Get column number of carriage return 5370 CMP hpos ;Is it greater than hpos? 5380 BCC cuover 5390 BEQ cuover 5400 SEC ;Yes, so calculate new value for count 5410 SBC hpos 5420 TAX 5430 JMP culoop ;and loop back 5440 .cuover STA hpos ;Store correct value in hpos 5450 .cunocr LDA vpos ;Are we on the top line? 5460 BNE cuover2 5470 JSR sdown ;Yes, so scroll down 5480 RTS 5490 .cuover2 DEC vpos ;Decrement vpos 5500 RTS 5510 .sdown LDA mempos ;Decrement menpos 5520 SEC 5530 SBC #&01 5540 STA mempos 5550 LDA mempos+1 5560 SBC #&00 5570 STA mempos+1 5580 LDY #&00 5590 LDA (mempos),Y ;Is there a carriage return at menpos? 5600 CMP #&0D 5610 BNE sdover 5620 LDA curpos ;Yes, so store curpos 5630 PHA 5640 LDA curpos+1 5650 PHA 5660 LDA mempos ;and transfer mempos into curpos 5670 STA curpos ;(nlcalc reads parameter from curpos) 5680 LDA mempos+1 5690 STA curpos+1 5700 JSR nlcalc ;Get column number of carriage return 5710 STA temp 5720 PLA ;Restore curpos 5730 STA curpos+1 5740 PLA 5750 STA curpos 5760 LDA mempos ;Subtract column number from mempos 5770 SEC 5780 SBC temp 5790 STA mempos 5800 LDA mempos+1 5810 SBC #&00 5820 STA mempos+1 5830 JMP sdout 5840 .sdover LDA mempos ;Set mempos to mempos-(length-1) 5850 SEC 5860 SBC #length-1 5870 STA mempos 5880 LDA mempos+1 5890 SBC #&00 5900 STA mempos+1 5910 .sdout RTS 5920 .sup LDX #length-1 ;Set count to length-1 5930 LDY #&00 5940 .suloop LDA (mempos),Y ;Is there a carriage return at mempos? 5950 CMP #&0D 5960 BEQ suout ;Yes, so exit loop 5970 INC mempos ;Increment mempos 5980 BNE suover 5990 INC mempos+1 6000 .suover DEX ;Update counter 6010 BNE suloop ;and exit loop if finished 6020 .suout INC mempos ;Increment meapos 6030 BNE suout2 6040 INC mempos+1 6050 .suout2 RTS 6060 .rubout LDA curpos ;Are we at textstart? 6070 CMP textstart 6080 BNE rok 6090 LDA curpos+1 6100 CMP textstart+1 6110 BNE rok 6120 LDA #&07 ;Yes, so beep and return 6130 JSR oswrch 6140 RTS 6150 .rok JSR cleft ;Move cursor left 6160 LDA curpos ;Copy curpos into temp 6170 STA temp 6180 CLC ;and copy curpos+1 into temp+2 6190 ADC #&01 6200 STA temp+2 6210 LDA curpos+1 6220 STA temp+1 6230 ADC #&00 6240 STA temp+3 6250 LDY #&00 6260 .rloop LDA (temp+2),Y ;Copy contents of teap+2 into tenp 6270 STA (temp),Y 6280 CMP #&FF ;Have we reached textend? 6290 BEQ rout 6300 INC temp ;Increment temp 6310 BNE rnoinc 6320 INC temp+1 6330 .rnoinc INC temp+2 ;Increment temp+2 6340 BNE rnoinc2 6350 INC temp+3 6360 .rnoinc2 JMP rloop 6370 .rout LDA textend ;Decrement textend 6380 SEC 6390 SBC #&01 6400 STA textend 6410 LDA textend+1 6420 SBC #&00 6430 STA textend+1 6440 RTS 6450 .write PHA ;Store A (holds value of key pressed) 6460 LDA textend ;Have we run out of memory? 6470 CMP #last MOD 256 6480 BNE wok 6490 LDA textend+1 6500 CMP #last DIV 256 6510 BNE wok 6520 LDA #&07 ;Yes, so beep, retrieve A and return 6530 JSR oswrch 6540 PLA 6550 RTS 6560 .wok LDA textend ;Copy textend into temp 6570 STA temp 6580 CLC ;and copy textend+1 into temp+2 6590 ADC #&01 6600 STA temp+2 6610 LDA textend+1 6620 STA temp+1 6630 ADC #&00 6640 STA temp+3 6650 LDY #&00 6660 .wloop LDA (temp),Y ;Copy contents of temp into temp+2 6670 STA (temp+2),Y 6680 LDA temp ;Decrement temp 6690 SEC 6700 SBC #&01 6710 STA temp 6720 LDA temp+1 6730 SBC #&00 6740 STA temp+1 6750 LDA temp+2 ;Decrement temp+2 6760 SEC 6770 SBC #&01 6780 STA temp+2 6790 LDA temp+3 6800 SBC #&00 6810 STA temp+3 6820 LDA temp+2 ;Have we reached curpos? 6830 CMP curpos 6840 BNE wloop 6850 LDA temp+3 6860 CMP curpos+1 6870 BNE wloop 6880 PLA ;Yes, so retrieve A 6890 STA (curpos),Y ;Insert character 6900 INC textend ;Increment textend 6910 BNE wnoinc 6920 INC textend+1 6930 .wnoinc JSR cright ;Move cursor right 6940 RTS 6950 .nlcalc LDA #&00 ;Start count at zero 6960 STA temp 6970 STA temp+1 6980 LDA curpos ;Copy curpos into temp+2 6990 STA temp+2 7000 LDA curpos+1 7010 STA temp+3 7020 LDA textstart ;Copy textstart-1 into temp+4 7030 SEC 7040 SBC #&01 7050 STA temp+4 7060 LDA textstart+1 7070 SBC #&00 7080 STA temp+5 7090 LDY #&00 7100 .nloop INC temp ;Update counter 7110 BNE noinc 7120 INC temp+1 7130 .noinc LDA temp+2 ;Decrement copy of curpos 7140 SEC 7150 SBC #&01 7160 STA temp+2 7170 LDA temp+3 7180 SBC #&00 7190 STA temp+3 7200 LDA (temp+2),Y ;Is there a carriage return there? 7210 CMP #&0D 7220 BEQ nout ;Yes, so exit loop 7230 LDA temp+2 ;Has copy of curpos hit textstart-1? 7240 CMP temp+4 7250 BNE nloop ;No, so loop back 7260 LDA temp+3 7270 CMP temp+5 7280 BNE nloop 7290 .nout LDA temp+1 ;Is count>length+1? 7300 BNE nover 7310 LDA temp 7320 CMP #length+1 7330 BCC nout2 7340 .nover LDA temp ;Yes, go subtract length from count 7350 SEC 7360 SBC #length 7370 STA temp 7380 LDA temp+1 7390 SBC #&00 7400 STA temp+1 7410 JMP nout 7420 .nout2 DEC temp ;Decrement temp 7430 LDA temp ;Return with wanted value 7440 RTS 7450 .buffer 7460 ] 7470 ENDPROC