There comes a time when once having learned the basics of machine language programming, to pursue the quest to write the ultimate program. For that noble endeavour, we need to equip ourselves with the proper tools.
For many years, “Artic Assembler” and “Hot-Z” were known as the utilites to use for writing machine language programs for the ZX/TS. Both utilites has its advantageous and disadvantageous. Both also resides in memory which limits where code could be stored. What if we had a tool which would not only allow us to write programs with the editing ease of the Artic Assembler, but would also allow us to generate code to any part of usable memory like Hot-Z, but without any of its restrictions? The answer, the cross assembler with the serial link.
Requirements:
1. PC compatible (with serial port)
2. Word Processor (ascii text option)
3. Z80 Cross Assembler (PseudoSam 80Z)
4. Modem program (ascii file send)
5. ZX/TS (w/64K, Ramdos, optional)
6. TS2050 serial port
7. Artic Assembler
One source for a Z80 cross assembler is the Vancouver Public Library. They offer a service called “PC-Sig”, which is a collection of PC, freeware and shareware programs. The utility is called “PseudoSam Cross Assembler 80z and 85.” This is a shareware program which means that there is a small registration fee if you do decide to use it.
The term “cross assembler” is used to describe this utility because it uses the PC compatible computer which has a 8088, 8086, 80286, or 80386 CPU, depending on whether it’s a PC, XT, AT, PS/2 etc., to generate code for the Z80 CPU, which the ZX/TS has.
Let’s begin with a demonstration. We’re going to put together two short programs. “TS1000 Name” will prints the name “Timex Sinclair 1000” on the screen and “Screen Inverse” will change characters on the screen to its inverse. To make things interesting, “TS1000 Name” will be located to address 9017D (Decimal) and “Screen Inverse” to location 32768D. The data for “TS1000 Name” will be located to address 49152D. (Choose different addresses if you don’t have 64K.) Use the word processor to produce this file which we will call “trial.asm” It is written in the format required by PseudoSam 80Z.
;--------< TS1000 Name >----------;
.org h'2339
initl: ld b,h'14 ; Set chr. countr.
ld hl,messg ; Move ch. pointer.
prnt: ld a,(hl) ; Get character.
rst h'10 ; Print it.
inc hl ; Update pointer.
djnz prnt ; Do it again until
ret ; messg is finish.
;-------< Screen Inverse >--------;
.org 32768
finds: ld hl,(16396) ; Find
inc hl ; start of screen.
row: ld c,24 ; Set row counter.
clumn: ld b,32 ; Set col. counter.
line: ld a,(hl) ; Change screen's
add a,128 ; normal
ld (hl),a ; characters
inc hl ; to
djnz line ; inverse and
inc hl ; inverse
dec c ; characters
jr nz,clumn ; to
ret ; normal.
;---------< Logo Data >-----------;
.org 49152
messg: .db h'b9,h'ae,h'b2,h'aa,h'bd,h'00
.db 56,46,51,40,49,38,46,55,0
.db 29,28,28,28,00
.end
;--------------------------------;
The word processor must be able, or have the option, to generate a pure ascii file. Any additional code embeded will confuse the assembler.
The PseudoSam version is different from most assemblers. It is based on the “Unix System V” assembler syntax. Notice the use of lower case letters, colons which follow after labels and periods which precede pseudo-ops.
Pseudo-ops are instructions used to inform the assembler. “.Org <address>” tells the assembler that the following code are to be written for this starting <address>. This allows us to choose where we want to place our code. We could even combine more than one program in the same listing. More information on pseudo-ops are found on the PseudoSam diskette.
Unlike the Artic Assembler, all numbers are concidered decimals unless specified otherwise and instructions are written in the traditional Zilog format. Notice the “h'” used to designate hex numbers and commas used in the instruction “jr nz,clumn”.
After this file is produced, assemble it with the cross assembler. Issue this command from DOS,
a80z trial.asm
which will produce two new files, trial.lst and trial.obj.
Trial.lst contains the program listing from trial.asm with the assembled code and their addresses in their respected columns. If any errors were reported in the assembling, the assembler will also mark its location in this file.
Trial.obj contains just the assembled hex codes arranged in what is known as the “Intel Hex” format. Here’s what it looks like (squeezed into 41 columns.)
:0B23390006142100C07ED72310FBC952
:108000002A0C40230E1806207EC680772310F923
01
:048010000D20F3C983
:10C00000B9AEB2AABD00382E332831262E37001D
16
:04C010001C1C1C00D8
:00000001FF
This file is divided into blocks. Each one contains the following information (in this order,)
1. A colon which marks the beginning of each block.
2. A number which indicates how many assembled “program” hex digits are in the block. “00” means the end of the file is reached.
3. The starting address for where the code should be stored.
4. A “00” hex digits. (Not used.)
5. Assembled hex codes in the block.
6. The checksum. This is the two’s complement (or if you prefer, the negative value) of all the digits in the block added together. It is used for detecting errors in the file transfer.
The PC will use the modem program to transfer this file over to the ZX/TS through the serial link. The protocal used will be 4800 baud, 8 data bits, no parity, 1 stop bit and using the “ASCII send” method. Each character in the file is sent one at a time until the entire copy of the file is received.
The ZX/TS will require a program which will accept and extract the necessary information from the file. Use the Artic Assembler to create “A80Z obj File Loader” This program will run when the command “RAND USR 16516.” is issued.
;---------------------------------;
; A80Z obj File Loader ;
; by V. Lee ;
;---------------------------------;
; This program will load A80Z's ;
; obj files from the PC to the ;
; ZX81/TS1000. ;
;---------------------------------;
fmode call 0f23 ; Go to fast mode.
init xor a ; Clear A.
ld c,a ; Clear
; checksum counter.
out 77,a ; Reset
out 77,a ;
out 77,a ; the
ld a,40 ; serial
out 77,a ; port.
ld a,4e ; Set mode, 8,n,1,
out 77,a ; 16x baud rate factr.
ld a,37 ; Set command to start
out 77,a ; communication.
fstrt call recv ; Search for
cp 3a ; the beginning
jr nz fstrt ; of the block.
call gbyte ; Is this
cp 00 ; the end
jr z exit ; of the file?
ld b,a ; Find # of hex digits
call gbyte ; to receive in block.
ld h,a ; Find
call gbyte ; memory address
ld l,a ; to load
call gbyte ; the code.
poke call gbyte ; Load
ld (hl),a ; the block
inc hl ; of code
djnz poke ; to memory.
call gbyte ; Continue only if the
jr z fstrt ; checksum is correct?
error ld a,13 ; Discontinue
call trans ; send.
ld hl,errm ; Report
jr print ; error message.
exit ld b,04 ; Get
echek call gbyte ; final
djnz echek ; digits
jr nz error ; Is checksum correct?
exit ld hl,downm ; Report dload cplete.
print ld b,12 ; Print
ploop ld a,(hl) ; the
inc hl ; message
rst 10 ; on the
djnz ploop ; screen.
call 0f2b ; Go to slow mode.
ret ; Return to BASIC.
gbyte call ghex ; Get
rlca ;
rlca ; most
rlca ; significant
rlca ; nibble.
ld d,a ; Save it.
call ghex ; Get LS nibble.
add a,d ; Add MSn to LSn.
ld d,a ; Save hex byte.
add a,c ; Update
ld c,a ; checksum.
ld a,d ; Get hex byte.
ret
ghex call recv ; Get ASCII character.
sub 30 ; If it is a ASCII no.,
cp 0a ; convert it to
ret c ; its hex value.
sub 07 ; If it is a ASCII let.
ret ; cvert to hex val.
recv in a,77 ; Has
bit 1,a ; character
jr z recv ; arrived?
in a,73 ; Get it.
ret
trans push af ; Save character.
tstat in a,77 ; Is
bit 0,a ; it time
jr z tstat ; to send?
pop af ; Get the character.
out 73,a ; Send it.
ret
errm "< error detected >"
downm "download completed"
;-------- end ----------;
This program also switches the ZX/TS to the fast mode to operate at the higher baud rates. Once the assembled program is loaded or if an error is detected, the ZX/TS is switched back to the slow mode. A message will be printed on the screen to inform if the transfer was successful or not. Remember to set the serial port dip switches for 4800 baud.
What may make this listing hard to follow is that,
1. Hex codes in the .obj file are all made up of two ascii characters. The loader has to convert each pair of ascii characters back to its original hex value.
2. Each hex digit in a block is totaled and then added to the checksum. If the result is “00” (ignoring the carry), then errors did not occur in the transfer.
The program also intializes the serial port and tracks the incoming and outgoing data. If there is interests on this topic, we’ll cover it in a future article.
Now let’s see if our demonstration program is really loaded into the ZX/TS. Run this BASIC program. Use the addresses that you’ve selected for the assembly, if you chosed different ones.
10 rand usr 9017
15 print
20 gosub 100
30 rand usr 32768
40 gosub 100
50 goto 10
100 for c=1 to 1
110 next c
120 return
The name “Timex Sinclair 1000” will be printed onto each line on the screen as it switches between normal and inverse.
What makes this system work so well is that most word processors are designed for editing. Features like block moves, block saves and word searches provides a real creative environment. In addition, the obj loader can also be rewritten to reside in low or in high memory. This allows REM statements in the “BASIC” area to store code. There are some excellent machine code routines available for generating big REM statements. Look for them in the club library.
What in store for the upcoming issues? We’ll find a way to get Hot-Z to disassemble code for PseudoSam 80Z, turn the TS2040 into a printer for the PC, and we may even cover how to program the serial port itself. In the meantime I’ll be on the look out for your ultimate program.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.