;-------------------------------------------------------------------- ; Here is your "Writing My First Program to Toggle into the Imsai ; 8080 (meaning the Z80Pack Frontpanel Imsai 8080 Emulator) ; Written by Lawrence Woodman on 5th November 2008 Techtinkering.com ; ------------------------------------------------------------------- ; Your program listing reformatted 7 September 2010 by Alan Spicer - ; in an attempt to make the program reloadable by this simulator ; without having to toggle the whole thing in every time! ; ------------------------------------------------------------------- ; Which brings us to ... how can we save it so it can be loaded? ; The simulator will take "-xFILENAME" to load a hex or bin file ; and thus can load it at program run (Power On) and execute it with ; almost no toggle switching at all. But how do we make a hex or bin ; file out of this thing? We copy and paste your SOURCE listing ... ; run it through a BUNCH of Unix/Linux utilties to try and get an ; Assembly Language Source File that *something* near to this sim ; can compile into bin or hex files. And so I did... ; ------------------------------------------------------------------- ; I found out that there is Z80ASM that Udo Munk wrote that comes ; with Z80pack, and also Z80ASM for Linux available elsewhere. ; Which one will win the prize first and compile without tons of ; fatal errors? Udo Munk's Z80asm won the prize. But not without a ; lot more work from me. Neither Z80ASM would take 8080 Assembler ; code, which is what Lawrence wrote this in. They wanted Z80 ; Assembler Mnemonics and ways of doing things. So off to a trans- ; lator near you to try and switch it over. Lots more Unix utils ; used to switch things over, like the VI Editor. ; ; It also seemed that the Z80asm didn't like certain length of ; LABELS in the program source code. They were not unique, it said. ; So fix that. And I still have 4 errors but it did compile to ; binary code. Both bin and hex files could be created. And they ; were. But something still seems to be wrong. The machine code ; that is generate does load into the sim machine. But it does not ; yet run. There still seems to be some bugs in a few spots where ; the Z80 machine code did NOT EQUAL the 8080 code? Or the hand ; code that you made? Did you really do this with no assembler? ; It's awful strange how you came out with such a listing???? ;------------------------------------------------------------------- ; After much work re-assembling and trying to fix those errors - ; I finally figured out how to kill those 4 errors. 2 each were ; the same, The assembler seems to like "FF" in "00ffh" format, ; and the IN and OUT data, also "FF"'s had to be in parenthesis. ; Imagine all of that???? It loads ok now from a HEX file and ; your program works. The bin file? I might be still doing something ; wrong with that. But this has been a LONG NIGHT/MORNING. ;------------------------------------------------------------------- ORG 0 ; ;----------------------------------- ; Initialise the register variables ;----------------------------------- ; LD C,00FFh LD D,1 ; ;----------------------------------------- ; Move the recorded position of the light ;----------------------------------------- ; LOOP: LD A,D ; Load Position into Accumulator CP 128 JP Z,SWDIR ; Position = 128? CP 1 JP NZ,MOVEPOS ; Position != 1? ; ; Switch the direction of the light ; SWDIR: LD A,C ; Load Direction into Accumulator CPL ; Compliment the accumulator LD C,A ; Store result back in the Direction MOVEPOS:LD A,C ; Load Direction into Accumulator CP 0 ; Direction != left? JP NZ,MOVERT ; ; Move position Left ; LD A,D ; Load Position into Accumulator RLA ; Rotate left LD D,A ; Store result back in the Position JP OUTPLGHT ; ; Move position Right ; MOVERT: LD A,D ; Load Position into Accumulator RRA ; Rotate right LD D,A ; Store result back in Position ; ;----------------------------------------------- ; Output the light to PROGRAMMED OUTPUT display ;----------------------------------------------- ; OUTPLGHT: LD A,D ; Load Position into Accumulator CPL ; Compliment Accumulator due ; to way PROGRAMMED OUTPUT works OUT (00FFh),A ; Output to PROGRAMMED OUTPUT ; ;----------------------- ; User controlled Delay ;----------------------- ; IN A,(00FFh) ; User delay from PROGRAMMED INPUT ; port 0xFF INC A ; Make sure 0 is minimum delay DLYOUTR:LD B,02 ; Set register B loop delay to 2 DLYINR1:LD E,00FFh ; Set register E loop delay to 255 DLYINR2:DEC E ; Decrement Register E JP NZ,DLYINR2 ; Loop until Register E = 0 DEC B ; Decrement Register B JP NZ,DLYINR1 ; Loop until Register B = 0 DEC A ; Decrement Accumulator JP NZ,DLYOUTR ; Loop until Register A = 0 ; ;------------------- ; Loop indefinitely ;------------------- ; JP LOOP END