i8080 programming (Lviv PC-01 examples)

8Bit, 16bit, Atari, Commodore, Apple, Spectrum, Acorn, TSR. All now defunked computer systems.

i8080 programming (Lviv PC-01 examples)

Postby Zelya » Fri Mar 28, 2014 2:16 pm

Hello!
As I think, a lot of us like old computers and games. But most of us think that game developing for ancient machines is a kind of magic. Yes, it's a little bit more difficult than Game Maker, but there is nothing impossible for people who can program a little in any language: Basic, Pascal, C, .NET. If you can think with algorithms, if you can imagine your game as mathematics structure, nothing can stop you with implementation your ideas on any platform you want.
So, I will try to introduce you the basics of assembler language for i8080 processor. As an example we will use my favorite PC-01 Lviv. Everybody who want to create programs for vintage computers will growth from basic assembler instructions writing to own simple game during my lessons. I hope, this topic will be useful for at least one person from this forum :)

Lesson 1. Environment. First program. PC-01 Lviv memory structure.
Before we can start our lessons we need three things.
First of all we need information about platform we want to develop for. Unfortunately there is no manuals about PC-01 Lviv in English and it's too hard to translate them. But I can provide you any information you need during my lessons. Also, we need some descriptions for i8080 instructions. You can easily find them in Google by "i8080 opcodes" or "i8080 instructions set" request. I can suggest you next link:
Code: Select all
http://comsci.us/cpu/8080/isindex.html

Don't be afraid! You shouldn't understand anything from this link now. But it would be useful for you later.
The second thing we need is a compiler which can create executable binary file form our assembler code. You are free to select any i8080 compiler. Most of them have the common syntax. But I will prepare example for one of them and I suggest you to use it for the first time before you become skilled to select your own environment. It will be online compiler Pretty 8080 Assembler:
Code: Select all
http://asdasd.rpg.fi/~svo/i8080/

Why I chose it? Because it is not so difficult to use it in browser. Also you can use in under any platform: Windows, Linux, Mac OS. Anything with JavaScript browsers support.
The last thing we need is emulator to run your programs. There are a lot of emulators with Lviv PC-01 support (for example: MESS). If you've tried any of them before to run games, you can use it in the same way. I will run my examples on this one (Windows):
Code: Select all
http://bashkiria-2m.narod.ru/files/emu.rar

You can just setup your system to open *.lvt files with emu.exe, and run programs by double click.

Now we have everything to prepare any program we want. Let's start studying. Try to put this code into Pretty Assembler left editor.
Code: Select all
begin .equ   08000h   ;start address

      .org   begin-16-6

      .db "LVOV/2.0/"
      .db 0D0h
      .db "PROGRM"
      .dw begin,end-1,start
start:

    MVI a, 0
    OUT 0C2h
    MVI a, 0
    STA 0BE38h
    CALL 0EBBCh
    MVI a, 255
    STA 5010h

end:

Be sure that the right part is refreshed (change mouse focus if it's needed) and press the "Make Beautiful Code" button.
Untitled1.png

Pretty Assembler will compile your code and suggest you to save test.bin file. Save it, rename to test.lvt file and run with your emulator. You will see the next image:
Untitled.png
Untitled.png (4.34 KiB) Viewed 3532 times

You can see the black screen with one small red line and "GO" word with cursor under it. "GO" and cursor are placed by PC-01 Lviv BIOS after your program execution. But the small red line on top - is the result of our program execution. Let's understand what our program too.
First of all we need to imagine the memory structure of PC-01 Lviv. I'll paint it for you:
Image
So, you can see the memory addresses at the right of image, from 0 to 64K. 64 Kilobytes is the largest memory which can be used by i8080. The gray area on the top called ROM is a Read Only Memory. This is a chip with hardcoded procedures (for example for word "GO" displaying) and other data. You can get values with addresses 48K - 64K, but you can't write anything there. In this case your program will be crashed.
The second block form top greed, called RAM - Random Access Memory (32K - 48K). This memory used in the way as on any computer. You can easily read data from it or write anything you want.
Let's talk about memory between 0 - 32K. As you can see this memory is slitted into two parts. PC-01 Lviv can work in two modes. The first mode (left part) allow you to work with 0-32K memory as a regular RAM. You can write and read values in the same way as in 32K - 48K. But you can change mode into the second version. In this mode 0-16K addresses are unacceptable. But the most interesting area is 16K - 43K. This is video memory. Any data you put there will be displayed on your screen.
And now lets look on our program. For the first time we will ignore this block:
Code: Select all
begin .equ   08000h   ;start address

      .org   begin-16-6

      .db "LVOV/2.0/"
      .db 0D0h
      .db "PROGRM"
      .dw begin,end-1,start
start:

This is file header. We will not change it, and I'll describe the sense of it later. We will work only with code between start and end labels:
Code: Select all
    MVI a, 0
    OUT 0C2h
    MVI a, 0
    STA 0BE38h
    CALL 0EBBCh
    MVI a, 255
    STA 5010h

First two lines turn our computer into the second mode (when we can access video memory). Next three lines called code from ROM (the upper read only memory) to clear the screen. And the last two lines put value 255 to the address 5010h (h - means hex value 5010h = 20496, win calc will help you :) )
Don't panic! Why and in what way we performed all these action you will get to know at the next lesson. But now you need just understand that we put number 255 to the address 5010h (20496).
But why we have red line for 255? I'll describe very shortly. More information you will get later. PC-01 Lviv has screen with resolution 256x256. It can use 4 colors at the same time. Now, lets calculate. We have totally 256*256 = 65536 (64K) pixels. One byte of memory allow us to code 256 different values. For example, VGA monitor in 256 color mode, has one byte of video memory for each pixel. Well, in the case of 16 colors, we can use one byte of information to store 2 pixels! And in the case of 4 colors we need one byte for 4 pixels!!! In this case we need 64K/4 = 16K of video memory to store all the PC-01 Lviv screen. And now look at the memory schema. We have this 16K between 16K - 32K addresses.
So, when the second mode is turned on, any byte placed between 16K - 32K addresses will code 4 pixels. If we put 255 value to the 16K address (16K = 16384 = 4000C) we will have red line with 4 pixels length at the top left corner of the screen. If we put 255 value to the 16K + 1 address, we will have the same line shifted 4 pixels to the right. And so on.
I've put the line at the 5010h address to see it at the central part of screen easy.
And the last hard thing we need to understand why we put value 255 and why the line is red. PC-01 Lviv has a lot of different palettes with 4 colors for each palette from 8 possible. The default palette has next colors (I will point also binary numbers of color with "b" letter):
0 (00b) - black
1 (01b) - blue
2 (10b) - greed
3 (11b) - red
As I told before, we code 4 pixels with one byte. Every byte consist of 8 bits. 255 value looks like 11111111b. PC-01 split in into two part.
--1--|--2--
1111|1111
Each pixel combines with one bit from 1st part and one bit from 2nd part. In our case we always have 11b which means red color. Lets change our 255 number to 240 = 11110000b
--1--|--2--
1111|0000
Now each pixel will have 10b color, and our line becomes green! Is it magic? You can try next value: 195 = 11000011b
--1--|--2--
1100|0011
In this case, first two pixels will be 10b - green, and the second two will be 01b - blue!
So, the first and one of the hardest lessons is finished. For the home task try to compile our program with different values for color and with different addresses of video memory to move line. Show me your results. Also ask any possible question. I understand that a lot of things can be now clear, but I'm not professional teacher and the first lesson is always one of the hardest.
Have a luck with your programming!
User avatar
Zelya
Next LVL Up at : 10
Next LVL Up at : 10
 
Posts: 8
Joined: Tue Apr 09, 2013 12:30 pm
Has thanked: 0 time
Been thanked: 16 times
Fav System: Not Sure

Re: i8080 programming (Lviv PC-01 examples)

Postby Hot Trout » Fri Mar 28, 2014 4:25 pm

Great topic and post and thank you for it. I amended the links to be inside CODE tags. This is a rule of the site regarding all external URL's.

Thank you for this and I hope everyone will get coding the next Atari 2600 game.

:goodpost: :thankyou:
Webmaster, Admin, Amiga Fan, Retro Gamer and Collector
Image
Image

Image
Click the banner to Join us on Discord
User avatar
Hot Trout
Unlimited Member
Unlimited Member
Next LVL Up at : 3650
Next LVL Up at : 3650
 
Posts: 3647
Joined: Mon Feb 01, 2010 6:42 pm
Location: UK
Has thanked: 2233 times
Been thanked: 1955 times
Fav System: Amiga
Steam ID: hot_trout

Re: i8080 programming (Lviv PC-01 examples)

Postby crustyasp46 » Fri Mar 28, 2014 9:04 pm

Good tutorial, but I have enough homework at the moment, trying to just figure out how to turn on some of the old stuff I have now. It seems every time I go to do something I spend more time on the net trying to find information. Oh, well, it is all fun. And hopefully at some time I get to try your tutorial out. :headbang:
:goodpost: :thankyou:
User avatar
crustyasp46
He's Everyones Daddy
He's Everyones Daddy
Next LVL Up at : 1750
Next LVL Up at : 1750
 
Posts: 1716
Joined: Sun Jun 06, 2010 11:06 pm
Has thanked: 2653 times
Been thanked: 1006 times

Re: i8080 programming (Lviv PC-01 examples)

Postby Dragon Mech » Sat Mar 29, 2014 1:34 pm

very nice Zelya. but i think i'll stick to coding weapons and monsters for zandronum ( doom, doom2, etc ). it's much closer to my skill level.
Site Moderator
For the Glory of the Gamer Nation!
Image
Image
User avatar
Dragon Mech
Site Moderator
Site Moderator
Next LVL Up at : 630
Next LVL Up at : 630
 
Posts: 613
Joined: Sun Mar 18, 2012 1:58 pm
Location: Somewhere out there.
Has thanked: 572 times
Been thanked: 358 times
Fav System: Too many to list here :D


Return to Retro Computing

Who is online

Users browsing this forum: No registered users and 10 guests