ZX81 Assembly on OSX

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
wietze
Posts: 12
Joined: Thu Jun 25, 2020 2:30 pm

ZX81 Assembly on OSX

Post by wietze »

Hi there guys,

Ive been looking around on the forum for a bit, and decided to try my luck by just posting the questions ;).

I am looking to code assembly for the ZX81. My computer is on 64bit OSX, and so far Ive installed EigthyOne using wine/emulation and Ive compile pasmo.

I was wondering if anyone could point me to some basic tutorials so I could get my feedback loop going like
- have a basic asm file
- assemble this with pasmo
- load result into emulator
- being able to run the code

So far I downloaded some hello world example from one of the forum posts that outputs a .p file. I tried to load this into EightyOne using `load tape' and then tried to run it using RAND USR VAL "16526" (and 16514) but nothing happens.

Would you guys be so kind to give me some pointers as to get my feedback loop running, so I can start exploring the Z80 commands and machine :)?

Kind regards,
Wietze
wietze
Posts: 12
Joined: Thu Jun 25, 2020 2:30 pm

Re: ZX81 Assembly on OSX

Post by wietze »

Ah right, I forgot that I had to push the play button on the tape manager to load the .p file.

It seems all is well. I can assemble the test program and run it!

Time to learn some z80!
Regards,
Wietze
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: ZX81 Assembly on OSX

Post by mrtinb »

Great to hear, that something is working.

If you need books to help you learn machine code, I have used these books.
  • If you would like to go down to a level where all can learn machine code (even children), I would recommend 'Machine Code for Beginners'. It teaches Z80 and 6502 for most microcomputers including instructions for ZX81. At the bottom of the page under the section 'Introduction to programming', there's a link to a PDF you can download.
  • A book dedicated to machine code on the ZX81 is 'Mastering Machine Code on your ZX81'. The book is found online as a website, where all examples can be downloaded as well. The book can also be found as a scanned PDF.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
wietze
Posts: 12
Joined: Thu Jun 25, 2020 2:30 pm

Re: ZX81 Assembly on OSX

Post by wietze »

Thanks! that is most definitely useful!

Ive started with ZX81Assembly.pdf by Timothy Swenson firstly, and Ill get through these as well!

Regarding CPU cycles (or are they called TStates here?); if the display is active, how many cycles does the ZX81 have for calculations each frame?

Regards,
Wietze
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: ZX81 Assembly on OSX

Post by mrtinb »

You can read on the detailed documentation of the ZX81, that is written for the emulator NO$ZX.

Here you can read that of the 3.25 MHz of the Z80 CPU, only 0.8045 MHz is used for your program. The rest of the CPU time is used for drawing the screen. For the "NTSC"/60Hz version it is even worse. Then only 0.5364 MHz is left for your program.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
wietze
Posts: 12
Joined: Thu Jun 25, 2020 2:30 pm

Re: ZX81 Assembly on OSX

Post by wietze »

Thanks!
wietze
Posts: 12
Joined: Thu Jun 25, 2020 2:30 pm

Re: ZX81 Assembly on OSX

Post by wietze »

I got this from the zx81Assembly.pdf; but it does not run correctly. Could it be that pushing and popping hl omitted and that PRINT taints it?
It seems to run correctly when I wrap push/pop around the print.
The other alternative is that I translated the PRINT call wrongly; I mapped it to BIOS (I guess) function :
- 0x10


Code: Select all

hello.asm:

   LD   HL,line
pline
   LD   A,(HL)
   CP   $ff
   JP   Z,end
   CALL PRINT
   INC  HL
   JP pline 
end
   RET

line:
.byte _H,_E,_L,_L,_O,$00,_W,_O,_R,_L,_D,$ff
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: ZX81 Assembly on OSX

Post by mrtinb »

Most calls to ROM uses the registers, so if you want them preserved, you need to save your own content on the stack with a PUSH before and POP after the call.

Like A is the main 8-bit register, then HL is the main 16-bit register. So these registers are always used by ROM.

B, C, D and E are less likely to be modified during ROM-call, but it depends on the call.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: ZX81 Assembly on OSX

Post by Moggy »

Some common ROM routines, their address in hex, new or old ROM and register use.
If there is any interest I can also scan the accompanying text to these routines taken from the book mentioned below, other wise the meanings should be clear enough.

In nearly every one the full register set is used so preserving values you have stored will be destroyed on return from any ROM routine in question, so preserving values you have put in these registers is essential as it cannot be assumed they won't be altered.

Taken from Advanced programming for the ZX81 By Mike Costello.

SLOW-0F2B USES ALL REGISTERS.

FAST-0F23 (OLD ROM-0F20) USES NO REGISTERS BUT SEE P167 SINCLAIR MANUAL

CHAR(PRINTS CHR WHOSE VALUE IS FOUND IN REGISTER A)-0010 USES ALTERNATE REGISTER SET (MAIN REGISTER SET POSSIBLY UNCHANGED)

CLS-0A2A USES ALL REGISTERS

BREAK-0F46(OLD ROM-0F43) USES ALL REGISTERS

BYTOUT(SEND ONE BYTE TO CASSETTE OUT PORT)-031E USES ALL EXCEPT HL

PRINTAT-08F5 USES ALL REGISTERS

PRINT$-0B6B USES ALL REGISTERS

(KEYBOARD) STROBE-O2BB USES HL,BC,A,D

DECODE-07BD USES ALL REGISTERS
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX81 Assembly on OSX

Post by 1024MAK »

It maybe worthwhile mentioning that a user program (BASIC or machine code) will only run at the maximum MPU speed if the machine is not generating a display, this is known as FAST mode. This is the same as the system used by the ZX80.

The normal ZX81 mode is SLOW mode, also known as compute and display. In this mode, generating a stable display is the priority of the system.

During the time that a (CRT beam) is scanning a pixel line, the system stops processing the user program (BASIC or machine code) and switches the Z80 MPU to display generation duties.

The Z80 works in conjunction with the ULA to fetch and process data from the display file, select the correct pixel pattern for the top character in the first character row to be displayed, and then the ULA converts this to a serial bit stream. Then the whole process repeats for the next character until the end of the line.

On the next pixel line, the process repeats again. This continues until all the pixel lines of a character row have been displayed. Then it starts all over again for the next character row, and continues until all character rows and hence the text/graphic area of the screen have been displayed.

This is the reason that so little processing time is left available to running user code. But the user gets a nice constant stable video picture.

Over the years, various clever programmers have found that by writing their own screen display routines, they can change the ratio between processor time for screen display and program time. One method is to display less screen data for example.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply