Created
April 26, 2012 12:01
-
-
Save DanielKeep/2499142 to your computer and use it in GitHub Desktop.
Floppy test program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can get a pre-generated disk image here: | |
http://ompldr.org/vZGlzZA/hello.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; This program expects a disk with a zero-terminated, pre- | |
; formatted string at the first sector. It will read the first | |
; sector, display the string, add the value 42 at offset | |
; 0x100, then write the buffer back to the second sector. | |
:START sub sp, 1 | |
; Map screen. Assuming screen = dev 0. Blame Bernard! | |
set a, 0 | |
set b, 0x8000 | |
hwi 0 | |
; Scan hardware list for floppy device | |
hwn i | |
sub i, 1 | |
:.query_device hwq i | |
ifn a, 0x4cae | |
set pc, .next_device | |
ifn b, 0x74fa | |
set pc, .next_device | |
; Found it! | |
set pc, .found_device | |
:.next_device ife i, 0 | |
set pc, .no_floppy | |
sub i, 1 | |
set pc, .query_device | |
:.no_floppy set a, NO_FLOPPY | |
jsr puts | |
jsr HALT | |
:.no_disk set a, NO_DISK | |
jsr puts | |
jsr HALT | |
:.read_failed set a, READ_FAILED | |
jsr puts | |
jsr HALT | |
:.write_failed set a, WRITE_FAILED | |
jsr puts | |
jsr HALT | |
:.found_device set [FLOPPY_DEVICE], i | |
set a, 0 | |
hwi [FLOPPY_DEVICE] | |
ife b, 0 | |
set pc, .no_disk | |
; Read sector 0 into memory | |
set a, 16 | |
set b, 0 | |
set c, 1 | |
set x, 0x7000 | |
hwi [FLOPPY_DEVICE] | |
ifn a, 0 | |
set pc, .read_failed | |
; Print the zero-terminated string at the start of the | |
; sector to screen. | |
set a, 0x7000 | |
jsr putsf | |
; Write 42 to offset 0x0100 and write back to sector 1. | |
set a, 0x7100 | |
set [a], 42 | |
set a, 17 | |
set b, 1 | |
set c, 1 | |
set x, 0x7000 | |
hwi [FLOPPY_DEVICE] | |
ifn a, 0 | |
set pc, .write_failed | |
jsr HALT | |
:puts set i, [.OFFSET] | |
set j, a | |
:.next ife [j], 0 | |
set pc, .end | |
set [i], [j] | |
bor [i], 0xF000 | |
add i, 1 | |
add j, 1 | |
set pc, .next | |
:.end set [.OFFSET], i | |
set pc, pop | |
:.OFFSET dat 0x8000 | |
:putsf set i, [puts.OFFSET] | |
set j, a | |
:.next ife [j], 0 | |
set pc, .end | |
set [i], [j] | |
; bor [i], 0xF000 | |
add i, 1 | |
add j, 1 | |
set pc, .next | |
:.end set [puts.OFFSET], i | |
set pc, pop | |
:HALT sub pc, 1 | |
:FLOPPY_DEVICE dat 0 | |
:NO_FLOPPY dat "No floppy drive!", 0 | |
:NO_DISK dat "No disk inserted!", 0 | |
:READ_FAILED dat "Read failed :'(", 0 | |
:WRITE_FAILED dat "Write failed :'(", 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment