Prev: 12A6 Up: Map Next: 1392
12B1: save_routine: Relocatable save page routine.
This routine is copied to RAM so that it can be run with the ROM paged out. The following 69 bytes are also copied.
save_routine 12B1 LD HL,pagename_string Copy pagename_string to RAM_pagename_string.
12B4 LD DE,RAM_pagename_string
12B7 LD BC,$000B
12BA LDIR
12BC LD A,(control_register) Load control_register and write it to control register with bit 3 set to page out ROM.
12BF OR $08
12C1 OUT ($7F),A
12C3 XOR A Set MODE system variable to 0 (C, K, or L).
12C4 LD ($5C41),A
12C7 LD A,$CC Set FLAGS system variable to $CC (printer mode L, keyboard mode L, numeric variable, execution).
12C9 LD ($5C3B),A
12CC LD A,$01 Call CHAN-OPEN routine to open stream 1 (keyboard).
12CE CALL $1601
save_routine_0 12D1 CALL $0D6B Call CLS routine.
12D4 LD A,$01 Call CHAN-OPEN routine to open stream 1 (keyboard).
12D6 CALL $1601
12D9 LD HL,RAM_pagename_string Set HL to RAM_pagename_string.
12DC LD B,$0B Set B to 11 as loop counter.
save_routine_1 12DE PUSH BC Loop through characters using RST $10 to print them to the lower screen.
12DF PUSH HL
12E0 LD A,(HL)
12E1 RST $10
12E2 POP HL
12E3 POP BC
12E4 INC HL
12E5 DJNZ save_routine_1
12E7 EI Enable interrupts.
12E8 LD HL,input_buffer Set HL to input_buffer.
12EB LD B,$0B Set B to 11 as loop counter to get a maximum of 11 characters.
save_routine_2 12ED PUSH BC Preserve registers.
12EE PUSH HL
save_routine_3 12EF LD A,($5C3B) Wait for bit 5 of FLAGS system variable to be set signalling a key has been pressed.
12F2 BIT 5,A
12F4 JR Z,save_routine_3
12F6 RES 5,A Clear new key flag.
12F8 LD ($5C3B),A
12FB LD A,($5C08) Read character from LAST-K system variable.
12FE CP $22 If key is '"' ignore and wait for another keypress.
1300 JR Z,save_routine_3
1302 CP $0D If key is 'enter' skip forwards to save_routine_4.
1304 JR Z,save_routine_4
1306 CP $20 If key is 'space' ignore and wait for another keypress.
1308 JR C,save_routine_3
130A CP $80 If key is greater than $7F ignore and wait for another keypress.
130C JR NC,save_routine_3
130E LD (HL),A Write the character to the buffer.
130F RST $10 Use RST $10 to print character to lower screen.
1310 POP HL Restore registers, increment HL, and loop.
1311 POP BC
1312 INC HL
1313 DJNZ save_routine_2
1315 JR save_routine_0 If loop is not broken early by the 'enter' key then jump right back to save_routine_0 to clear the screen and try again.
save_routine_4 1317 POP HL Balance the stack.
1318 POP BC
1319 LD (HL),A Store key ('enter' character) in buffer.
131A LD A,B If counter value is still 11 (no characters entered) then jump right back to save_routine_0 to clear the screen and try again.
131B CP $0B
131D JR Z,save_routine_0
131F DI Disable interrupts.
1320 LD A,(control_register) Write control_register to control register to page ROM in.
1323 OUT ($7F),A
1325 LD DE,($5C59) Copy first part of save_instruction string to address in E_LINE system variable.
1329 LD HL,save_instruction
132C LD BC,$000C
132F LDIR
1331 LD HL,input_buffer Append characters from filename input buffer, up to but not including the 'enter' character.
save_routine_5 1334 LD A,(HL)
1335 CP $0D
1337 JR Z,save_routine_6
1339 LD (DE),A
133A INC DE
133B INC HL
133C JR save_routine_5
save_routine_6 133E LD HL,$13A0 Append second part of save_instruction string.
1341 LD BC,$0014
1344 LDIR
1346 EX DE,HL Set STKBOT, STKEND, and WORKSP system variables to end of entered instruction.
1347 LD ($5C63),HL
134A LD ($5C65),HL
134D LD ($5C61),HL
1350 CALL clear_screen Call clear_screen to clear the screen.
1353 CALL decode_page Decode and render page.
1356 LD A,(control_register) Load control_register and write it to control register with bit 3 set to page out ROM.
1359 OR $08
135B OUT ($7F),A
135D EI Enable interrupts.
135E LD HL,($5CB2) Reset stack below RAMTOP.
1361 DEC HL
1362 LD SP,HL
1363 LD HL,($5C59) Copy address in E_LINE system variable to CH-ADD system variable (address of next character to be interpreted).
1366 LD ($5C5D),HL
1369 LD A,$07 Set BORDCR system variable to $07 (black).
136B LD ($5C48),A
136E CALL $19FB Call E-LINE-NO routine.
1371 LD HL,$5C3B Set bit 7 of FLAGS system variable (execution).
1374 SET 7,(HL)
1376 LD HL,$5C3A Set ERR-NR system variable to $FF (error 0).
1379 LD (HL),$FF
137B LD A,$01 Set NSPPC system variable (statement in line to be jumped to) to 1.
137D LD ($5C44),A
1380 CALL $1B8A Call LINE-RUN to execute the BASIC line.
1383 DI Disable interrupts.
1384 LD A,(control_register) Write control_register to control register to page ROM in.
1387 OUT ($7F),A
1389 LD HL,($5CB2) Reset stack below RAMTOP.
138C DEC HL
138D LD SP,HL
138E LD HL,(save_return_pointer) Jump to address in save_return_pointer.
1391 JP (HL)
Prev: 12A6 Up: Map Next: 1392