ПК-01 ЛЬВОВ

форум о ПК-01,02 "Львов"
Текущее время: 22 ноя 2017, 21:41

Forum Games WEB Tape Loader Twitter RSS

Часовой пояс: UTC + 2 часа [ Летнее время ]




Начать новую тему Ответить на тему  [ 1 сообщение ] 
Автор Сообщение
 Заголовок сообщения: i8080 programming (Lviv PC-01 examples)
СообщениеДобавлено: 29 мар 2014, 00:43 
Не в сети
Site Admin
Аватар пользователя

Зарегистрирован: 24 июл 2008, 12:05
Сообщений: 978
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:
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:
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):
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.
Код:
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.
Изображение
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:
Изображение
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:
Изображение
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:
Код:
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:
Код:
    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!


Вернуться наверх
 Профиль  
 
Показать сообщения за:  Сортировать по:  
Начать новую тему Ответить на тему  [ 1 сообщение ] 

Forum Games WEB Tape Loader Twitter RSS

Часовой пояс: UTC + 2 часа [ Летнее время ]


Кто сейчас на форуме

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1


Вы не можете начинать темы
Вы не можете отвечать на сообщения
Вы не можете редактировать свои сообщения
Вы не можете удалять свои сообщения
Вы не можете добавлять вложения

Найти:
cron
Free counters!
Powered by phpBB® Forum Software © phpBB Group
Русская поддержка phpBB