I lost 2 days – one to being knocked out by the booster, and the other from apathy, laziness, and distractions. That’s so fucking like me… OK, back at it. I doubt I’m going to get a light blinking today, but I’m going to dig into what It’ll take to get a timer set up in Assembly language.
The Z80 CTC first expects a Channel Control word, which is optionally followed by a Time Constant. The Control Word is a series of 8 bits, each of which represents a single toggle, outlined below (I recreated this table from this video). We could assemble this byte a few different ways:
- Hard code it – 00010101B would be a control word, followed by a time constant, rising edge. The assembler wants the B suffix for binary. Efficient, but dumb.
- Assign each bit it’s decimal or hex value, and then add them up together. To get the same word as above, we’d do (128*0)+(64*0)+(32*0)+(16*1)+(8*0)+(4*1)+(2*0)+(1*1)
- Have 8 discrete 1 bit values, and left shift them onto the accumulator – Bit 7 would be shifted 7 times, bit 6 shifted 6 times, etc…
Lets first experiment with shifting a value. But even before we do that, we have to see about prompting the user with what to enter. JFC, you gotta do everything yourself in assembly.
OK, I’ve been trying to write a simple god damn message to the terminal for the last 90 minutes.
; HELLO WORLD
; SETUP SOME THINGS
BDOS EQU 5
WCONF EQU 2
RCONF EQU 1
RBOOT EQU 0
TPA EQU 100H
CR EQU 0DH
LF EQU 0AH
CTRLZ EQU 1AH
ORG TPA
START1: LD E,LF ;OUTPUT LINE FEED
LD C,WCONF
CALL BDOS
DERP: LD E,'$' ;OUTPUT A $
LD C,WCONF
CALL BDOS
MESG: DB "HELLO WORLD!"
LD HL,MESG
PRNT: LD E,(HL) ;HL POINTS TO CHAR TO LOAD INTO A
INC HL ;INCREMENT HL
LD C,WCONF ;SET C W/ WRITE BYTE
CALL BDOS
JP PRNT ;GO BACK TO THE TOP OF THE PRINT ROUTINE
Code language: PHP (php)
I hate this.
UPDATE:
I’m dumb. I rewrote the program after some folks pointed out a few extra-stupid mistakes, and it at least now vomits onto the screen!
Gotta have the DB block at the end, otherwise it’s just interpreted as code (duh)
Gotta PUSH & POP the HL register, cause it gets trashed by the BDOS Call.
What you see below is what happens when you don’t have a test at the end of the string. The loop is printing everything (the contents of the entire memory map).