I Aten't Ded

If you can’t learn to ride an elephant, you can at least learn to ride a horse.

Hiatus

Furlough ended so hobbies have been abandoned for a while until I got adjusted to being back at work and working from home. A new routine has been established so it’s time to pick where I left off. Which means remembering how to encode x86 instructions, I’m so happy I wrote that journal page.

Rehab

Since it’s the first time picking the hammer back up we’re going to keep things nice and simple.

This is a tiny component that clears the screen. I’ve tried to make it somewhat reusable and, gasp, give actual feedback about if it was successful. For this component pattern I’ve decided to use the carry flag to indicate success/failure of the operation, which I think might be quite common when using assembly. Flag set is error, flag clear is success.

#-------------------------------------------------------------------------------
# Clear a screen page in 80x25 16-colour text mode
#
# Notes:
#   In this mode each character on screen is represented by 1-byte for character 
#   followed by 1-byte for colour. Video memory allows for 8 pages of which only
#   one is displayed to the user.
#
# Inputs:
#   AL - Page to clear
#
# Destroys:
#   AX, BX, CX, ES, DI
#-------------------------------------------------------------------------------

# First need to figure out which page we're on
2100: cmp al, 08            3c 08
2102: jg error              7f 17

# One page is 80x25x2 bytes long
2104: mov bx, 0fa0          bb a0 0f
2107: mul bx                f7 e3

# DI holds the offset into video memory for the later stosw operation
2109: mov di, ax            89 c7

# Load up ES to point to the segment containing video memory
210b: mov ax, b800          b8 00 b8
210e: mov es, ax            8e c0

# Set entire screen to ASCII null with grey on black colour
2110: mov ax, 0700          b8 00 07
2113: mov cx, 07d0          b9 d0 07
2116: rep stosw             f3 ab
2118: clc                   f8
2119: jmp end               eb 01

error:
211b: stc                   f9

end:
211c: retf                  cb

I don’t store the contents of incoming registers, that’s the responsibility of whatever called this component. Because whatever called it knows whether or not the register contents matter.

The cursor position hasn’t been reset and that’s deliberate. Later there will be some component that through composition clears the screen and then resets the cursor. Composition is going to be fundamental throughout this entire project.

We also need a little stub for testing because the Enbugger has no way of setting registers before making the call. Since everything past address 3000 doesn’t get saved we can use that as a scratchpad.

3000: xor ax, ax        31 c0
3002: call 0000:2100    9a 00 21 00 00
3007: retf              cb

This sets the pattern for the coming weeks. There will a lot of little components to write and once I’ve got all those that I think are required a start can be made on writing a hex editor, which I’ve decided is going to be the first major target.

Onward and Upward!

— Curufir