Showing posts with label Briel Altair 8800. Show all posts
Showing posts with label Briel Altair 8800. Show all posts

Tuesday, April 15, 2014

Yum Game ported to BDS C

I've been playing some more with the Briel Altair 8800 running CP/M.

As a larger test of the BDS C compiler I was able to port the "Yum" game that I originally wrote to run on the Briel Apple Replica 1.

Porting it to BDS C was a few hours of work (mostly spent transferring new versions of the code between my Linux desktop and SD card and compiling on the Altair 8800.

The changes required were not too major. I was impressed by the reasonably complete run-time library included with BDS C. In all, the changes I had to make were the following:

  • Includes changed (BDSC C has everything in stdio.h).
  • sizeof does not work for arrays, so used a constant.
  • Arrays cannot be initialized, but can use initptr() function instead.
  • No bool type, so use int.
  • Function declarations have to use old K&R format.
  • Text supports lower case (original Apple 1 version had to be upper case only).
  • Some text lines (like help) made wider due to 80 column screen.
  • Variables cannot be initialized when declared.
  • No strtol() so use atoi().
  • Remove const qualifiers.
  • Clear screen using ANSI escape sequence.

Below is a partial log of a session playing the game against the computer.



#     # #     # #     #
 #   #  #     # ##   ##
  # #   #     # # # # #
   #    #     # #  #  #
   #    #     # #     #
   #    #     # #     #
   #     #####  #     #


Welcome to Yum!
Do you want instructions (y/n) ? y

This is a computer version of the game Yum, similar to games known as Yahtzee,
Yacht and Generala. Each player rolls five dice up to three times and then
applies the dice toward a category to claim points. The game has 12 rounds
during which each player attempts to claim the most points in each category.

The winner is the person scoring the most points at the end of the game.
This version supports up to three players of which any can be human or
computer players.

Categories are as follows:
1'S through 6'S - dice of same type
Low Straight (15) - 1 2 3 4 5
High Straight (20) - 2 3 4 5 6
Low Score - total 21 or more
High Score - total 22 or more
Full House (25) - 3 of a kind and pair
Yum (30) - 5 dice the same
Bonus of 25 points if upper section is 63 or more.

How many human players (0-3)? 1
How many computer players (0-2)? 1
Name of player 1? Jeff
Press to start the game
Wait a few seconds, and type a CR: 

Jeff's turn. Press to roll 
First roll is: 2 2 2 4 5
Enter dice to roll again or D for dice or S for score: 4 5
Second roll is: 2 2 2 2 2
Enter dice to roll again or D for dice or S for score: 

 1  - 1'S
 2  - 2'S
 3  - 3'S
 4  - 4'S
 5  - 5'S
 6  - 6'S
 9  - Low Straight
10  - High Straight
11  - Low Score
12  - High Score
13  - Full House
14  - Yum

Jeff, What category do you want to claim? (1-14)? 14

Altair's turn. Press to roll 
First roll is: 1 1 4 4 5
Altair keeps: 1 1 4 4
Second roll is: 1 1 4 4 5
Altair keeps: 1 1 4 4
Last roll is: 1 1 2 4 4
Altair plays 1'S

Press to continue 

Score after 1 of 12 rounds:

Roll           Jeff    Altair  
1'S                    2       
2'S                            
3'S                            
4'S                            
5'S                            
6'S                            
Sub-total      0       2       
Bonus          0       0       
Low Straight                   
High Straight                  
Low Score                      
High Score                     
Full House                     
Yum            30              
Total          30      2       

Press to continue 

Jeff's turn. Press to roll 
First roll is: 1 2 2 6 6
Enter dice to roll again or D for dice or S for score: 1
Second roll is: 2 2 4 6 6
Enter dice to roll again or D for dice or S for score: 4
Last roll is: 2 2 6 6 6

 1  - 1'S
 2  - 2'S
 3  - 3'S
 4  - 4'S
 5  - 5'S
 6  - 6'S
 9  - Low Straight
10  - High Straight
11  - Low Score
12  - High Score
13  - Full House

Jeff, What category do you want to claim? (1-14)? 13

Altair's turn. Press to roll 
First roll is: 2 4 4 6 6
Altair keeps: 4 4 6 6
Second roll is: 4 4 4 6 6
Altair keeps: 4 4 4 6 6
Altair plays Full House

Press to continue 

Score after 2 of 12 rounds:

Roll           Jeff    Altair  
1'S                    2       
2'S                            
3'S                            
4'S                            
5'S                            
6'S                            
Sub-total      0       2       
Bonus          0       0       
Low Straight                   
High Straight                  
Low Score                      
High Score                     
Full House     25      25      
Yum            30              
Total          55      27      

Press to continue


I put the source code as well as a CP/M binary here on github.  Next, I plan to try porting my text adventure game.

Sunday, March 30, 2014

JMON - 8080 Version

I wanted to learn some Intel 8080 assembler programming, so I selected as a project to write a port of my JMON machine language monitor program that I wrote for the 6502 and Briel Apple 1 Replica.

After a couple of evenings of hacking I have a version running with six of the commands implemented. It is not so much a port, as an implementation from scratch of a subset of the commands and features of the 6502 version.

Some sample output is shown below (user input is in bold).

JMON Monitor 0.1 by Jeff Tranter
? ?
Valid commands:
C start end dest           Copy memory
D address                  Dump memory
F start end data...        Fill memory
G address                  Go
I                          Show info
K start end                Checksum
L                          Clear screen
R                          Examine registers
S start end data...        Search memory
T start end                Test memory
V start end dest           Verify memory
: address data...          Write to memory
= address +/- address      Hex math calculation
?                          Help

? I
JMON Monitor 0.1 by Jeff Tranter
CPU type: 8080

? R
A=00 BC=0000 DE=0000 HL=0000 F=00000110 SP=7000 PC=0000

? D 0000
0000: 32 9E 06 78 32 A0 06 79 32 A1 06 7A 32 A2 06 7B 2..x2..y2..z2..{
0010: 32 A3 06 7C 32 A4 06 7D 32 A5 06 F5 C1 79 32 9F 2..|2..}2....y2.
0020: 06 21 00 70 7C 32 A6 06 7D 32 A7 06 31 00 70 CD .!.p|2..}2..1.p.
0030: E5 02 21 A7 03 CD EC 02 3E 3F CD 92 02 CD FC 02 ..!......?......
0040: CD A1 02 CD 04 03 FE 43 C2 51 00 CD 85 02 C3 38 .......C.Q.....8
0050: 00 FE 44 C2 5C 00 CD EC 00 C3 38 00 FE 46 C2 67 ..D.\.....8..F.g
0060: 00 CD 85 02 C3 38 00 FE 47 C2 72 00 CD 4A 01 C3 .....8..G.r..J..
0070: 38 00 FE 49 C2 7D 00 CD 90 01 C3 38 00 FE 4B C2 8..I.}.....8..K.
0080: 88 00 CD 85 02 C3 38 00 FE 4C C2 93 00 CD 89 01 ......8..L......
0090: C3 38 00 FE 52 C2 9E 00 CD BC 01 C3 38 00 FE 53 .8..R.......8..S
00A0: C2 A9 00 CD 85 02 C3 38 00 FE 54 C2 B4 00 CD 85 .......8..T.....
00B0: 02 C3 38 00 FE 56 C2 BF 00 CD 85 02 C3 38 00 FE ..8..V.......8..
00C0: 3A C2 CA 00 CD 85 02 C3 38 00 FE 3D C2 D5 00 CD :.......8..=....
00D0: 85 02 C3 38 00 FE 3F C2 E0 00 CD 7B 02 C3 38 00 ...8..?....{..8.
00E0: CD AB 02 21 CA 03 CD EC 02 C3 38 00 CD 92 02 CD ...!......8.....
00F0: FC 02 CD 9C 03 D2 FC 00 CD AB 02 C9 CD AB 02 0E ................
0100: 18 E5 CD 43 03 3E 3A CD 92 02 06 10 CD FC 02 7E ...C..:........~
0110: CD 11 03 23 05 C2 0C 01 CD FC 02 E1 06 10 7E CD ...#..........~.
0120: D0 02 23 05 C2 1E 01 CD AB 02 0D C2 01 01 E5 21 ..#............!
0130: 51 06 CD EC 02 E1 CD A1 02 FE 1B C2 42 01 CD AB Q...........B...
0140: 02 C9 FE 20 CA FC 00 C3 36 01 CD 92 02 CD FC 02 ... ....6.......
0150: CD 9C 03 D2 5A 01 CD AB 02 C9 22 A8 06 CD AB 02 ....Z.....".....
0160: 2A 00 00 E5 3A A8 06 6F 3A A9 06 67 E5 3A A4 06 *...:..o:..g.:..
0170: 67 3A A5 06 6F 3A A2 06 57 3A A3 06 5F 3A A0 06 g:..o:..W:.._..
Press Space to continue, ESC to stop 

? G 0000

It builds using the AS Macro Assembler. The binary can be put on an SD card and directly loaded into the Briel Altair 8800 memory and run.

I found debugging quite straightforward by using the front panel switches of the Briel Altair 8800. In particular, the ability to step, see disassembly on the console, and set a breakpoint address, were very useful. The JMON monitor makes some things a little easier than the front panel, like dumping the contents of memory.

While my goal was to learn 8080 assembly language programming, the monitor is somewhat useful in it's current form. You can find the source code here. It is licensed under the Apache 2.0 license so you are free to use it for any purpose. As time allows, I may implement more commands and features.

Being mostly familiar with the 6502, and its successors like the 6809 and 68000, it was interesting to see how the Intel 8080 compared. It has more registers and instructions than the 6502, making some things easier, but the learning curve is perhaps higher. It also has a few unusual instructions and quirks (for example, how do you clear the carry bit?).

The AS Macro Assembler

I was recently writing some Intel 8080 assembly language code for the Briel Altair 8800 computer. Assembling programs by hand and toggling in the binary codes using the front panel gets tedious very quickly. I could write it under CP/M and use the CP/M assembler, but text editing is a little clumsy under CP/M, the assembler is slow, and I want to run the programs standalone on the Altair 8800 without using CP/M.

A search for a cross-assembler that would run on Linux and support the Intel 8080 identified the AS macro assembler. This is a full-featured, free (GPL licensed) cross-assembler that runs on Linux and other desktop operating systems. It actually supports about 75 different microprocessors -- quite an amazing accomplishment!

I built it from source on Linux without any problems and was soon assembling 8080 assembly language code. The documentation that comes with it is very extensive and complete and the assembler listings are easy to read (some representative listing code is shown below).

727/     39F :                     ; GetAddress
728/     39F :                     ; Gets a four character hex number from the keyboard.
729/     39F :                     ; Ignores invalid characters. cancels and sets carry bit.
730/     39F :                     ; Returns binary word in HL.
731/     39F :                     ; Registers affected: A,B,H,L
732/     39F :                     
733/     39F :                     GetAddress:
734/     39F : CD 90 03                    call    GetByte         ; Get MSB
735/     3A2 : D8                          rc                      ; Exit if pressed
736/     3A3 : 67                          mov     h,a             ; Save MSB in H
737/     3A4 : CD 90 03                    call    GetByte         ; Get LSB
738/     3A7 : D8                          rc                      ; Exit if pressed
739/     3A8 : 6F                          mov     l,a             ; Save LSB in L
740/     3A9 : C9                          ret

It can produce Intel Hex format files which can be transferred to CP/M, converted to .COM files using the CP/M LOAD program, and then executed.

I am using it to generate a binary file which can be copied to an SD card and then directly loaded and executed by the firmware on the Briel Altair 8800.

It is very fast to assemble programs under Linux, and seems to have all the features and more than I could want. If you are looking for a good cross-assembler for the 8080 or just about any processor, it may be just what you need.