Videopac / Odyssey2 forum
August 06, 2021, 05:58:36 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Join Rafael's Haunted Woods contest and win a copy of the game!
 
   Home   Help Login Register links videopac.nl  
Pages: [1]   Go Down
  Print  
Author Topic: C7420 emulator with BBC Basic  (Read 5733 times)
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« on: June 01, 2011, 11:46:13 PM »

some fiddling with another Basic in the C7420/Z80 mbed emulator.

This is one of my all time favorite Basics: BBC Basic, it even has a built in (Z80!) assembler and allows structural programming with functions, procedures full variable names etc. And it is M$ free...

So far I can enter a program but can not run it yet (it hangs after RUN).
In direct mode it executes the commands and calculations (5 byte floats!) OK.

Below is a picture of the first words spoken by BBC basic on a Videopac G7400...
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
manopac
Game & App Development
Give this man a Jopac!
*
Posts: 1157



« Reply #1 on: June 02, 2011, 08:09:07 PM »

I declare you officially crazy  Wink

but I just LOVE the stuff you are doing ... I wish I had a clue how to do these things ...
Logged

sex, lies, and videopac
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #2 on: June 02, 2011, 08:52:30 PM »

Hehe... Well, it started with a Z80 emulator and a Videopac and then it got a little out of control  Roll Eyes the mbed is such a nice toy to play with.

While browsing on the web I stumbled upon BBC Basic (Z80 version) and it had been ported to a wide variety of computers and processors.   
Nice thing about the BBC Basic is that, on the original BBC computer, the default screen mode was a 'Teletext' mode so I thought it would be an ideal candidate to port to the G7400 (and maybe the VG5000) since the graphic chips are so Teletext related.

There still is a recent (commercial) version of BBC Basic for Windows (....) but the older Z80/6502/etc versions are free to download.
Only problem is there is no source available but you can find lots of documentation on the internals of the Basic (OS calls/vectors etc.)
After some moving about of the emulated ram and rom blocks I could intercept the input and output vectors and redirect them to the G7400 in much the same way the C7420 Basic module originally communicates with the G7400.

BTW, if I start a Basic program with 'GOTO' instead of 'RUN' it works, not sure why it locks up with RUN..
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
manopac
Game & App Development
Give this man a Jopac!
*
Posts: 1157



« Reply #3 on: June 03, 2011, 08:05:59 PM »

After some moving about of the emulated ram and rom blocks I could intercept the input and output vectors and redirect them to the G7400 in much the same way the C7420 Basic module originally communicates with the G7400.

I would be actually quite intrested in how that communication works ... can you post some details ? (this might motivate me into finally adding a C7420 emulation to O2EM ...)
Logged

sex, lies, and videopac
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #4 on: June 04, 2011, 12:12:17 AM »

I would be actually quite intrested in how that communication works ... can you post some details ? (this might motivate me into finally adding a C7420 emulation to O2EM ...)

The basic principle is the G7400 (8048) communicates over a input and output latch to the C7420 (Z80) with two handshake lines: one line (T0) comes from a flipflop which is set by writing the latch from the Z80 and reset by a read of the latch by the 8048. This flipflop is also readable by the Z80 so it knows the 8048 has read the latch.

The other line comes from the 8048 and triggers the interrupt line from the Z80 so it knows there is a byte to be read from the 8048. The 8048 can also activate the reset line of the Z80. The latch and control lines are memory mapped in the 8048 address space. The Z80 uses its dedicated IO space for writing the latch and reading the flipflop.

The T0 line (signaling a byte from the Z80 is available) is read in the VSYNC interrupt of the 8048, if no signal has been given by the Z80 the 8048 just scans the keyboard, joysticks, collision registers etc. and sends a packet of data to the Z80 (every VSYNC).

All you need to do is setup a separate thread with a Z80 emulator, setup the Z80 memory (ram/rom) and assign the latches and handshake lines and it should work.

My mbed C7420 emulation module has both latches (in a single register chip) and a seperate flipflop for the handshake, the C7420 Videopac cartridge is a 100% copy of the original C7420 cartridge.

The chess module works almost the same but it does not use the T0 line, it just reads the latch and waits for sensible data...
In theory you could emulate the Z80 part of chess module also in O2EM.
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #5 on: June 04, 2011, 12:19:15 AM »

BTW.. my Z80 emulator just runs as fast as it can on the mbed, for O2EM this might be good or bad..

Good: Chess will respond almost instantaneous, and Basic will be quite fast
Bad: It will not feel like the real thing..

On the other hand, the biggest slowdown is the communication with the 8048, the Basic module keeps a seperate video rambuffer and has to copy it line by line to the 8048 which has to copy it to the plus graphics chips..
Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
manopac
Game & App Development
Give this man a Jopac!
*
Posts: 1157



« Reply #6 on: June 04, 2011, 01:12:46 AM »

ok ... understand the principle :-) thanks !!

how did you get the Acorn Basic to produce output on G7400 then ?? you must have implemented the protocol the Z80 and the C7420 Videopac cart use by yourself, right ?
Logged

sex, lies, and videopac
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #7 on: June 04, 2011, 06:53:27 PM »

In theory you could pull the C7420 Rom out of the module and replace it with a modified BBC Basic Z80 rom. My C7420 module is emulated by the mbed. On the mbed runs the Z80 emulator and  I can program any Z80 rom I want and have that code executed by the Z80 emulator. BBC Basic is heavily vectorised in all in and output so all I need to do in the emulator is to catch the correct program counter address and act upon the values given in the registers, for now I have programmed the responses in C and just force a RET at the end of my routines and let the Z80 carry on after that. When it has to run in native Z80 I need to program the in and output routines in Z80 assembler. Problem now is that the BBC Basic version I have used (the CP/M version) needs to be relocated so it uses the ROM and RAM space of the C7420 module, and for that I need to run BBC basic as the relocator program suppiled with the package is written in BBC Basic (talk about a chicken and egg problem). I hope to figure out the RUN lockup problem this weekend so I can relocate the ROM and RAM and also get LOAD and SAVE working to the microSD card.

I had figured out the routines to communicate with the G7400 earlier, there is a topic in Hardware http://videopac.nl/forum/index.php?topic=1616.0 which showed 'Hello World from mbed to Videopac' or something like that. So it was basically connecting the dots.
« Last Edit: June 05, 2011, 10:10:55 AM by gertk » Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #8 on: June 04, 2011, 09:33:01 PM »

Ha, the RUN problem was a nice one to tackle... Somewhere after entering RUN the Basic reads the refresh counterregister (R) with a:

Code:
X0d7a: ld a,r ; 0d7a  ed 5f
jr z,X0d7a ; 0d7c  28 fc

and waits for it to change (for randomness maybe ?) and my Z80 emulator did not update this register.. Well, this one took me only an hour or two...  Cheesy
But it runs! Albeit slow because of all the debugging code still dangling inside but nevertheless...

I removed the (in BBC basic) useless statusline on top of the screen, it slowed down the output even more...
« Last Edit: June 14, 2011, 08:51:03 PM by gertk » Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
gertk
Post Axe Pete!
*****
Posts: 866



gertk64
WWW
« Reply #9 on: June 14, 2011, 09:18:35 PM »

The picture above shows part of a sample BBC basic program called 'guess the animal' which the emulator loads just fine.
Most of the in and output stuff works, file saving/loading to the microSD card, text color, cursor is active and can be positioned, selfdefined characters work but the teletext graphics are a pain since the whole screen rambuffer needs to be transferred to the G7400 through some interpreter code which checks for an 'end of data' byte ($90) but these are used in the attributes of the G7400 graphics chip too as valid codes so after trying to transfer that to the G7400 it crashes :-)

There is another copy routine in the cartridge rom that can handle multiple chunks of 256 bytes words max but does not check the individual bytes but this routine switches the screen off during transfer (why?) so it blinks like mad during scrolling (remember ZX80?) It is much faster though and accepts all codes....

BTW the self defined characters as described in the C7420 manual have a nice quirk:

The bit order seems to be the exact opposite of the order described: bit 7 is the rightmost bit of the pattern instead of the leftmost, at least when I do a (in BBC Basic):  

VDU &17,160,128,128,64,32,16,8,4,2,1,1  (aka SETET or SETEG 032,"80804020100804020101")

(this means define character 160 with 10 byte patterns following)
I would expect that I get a 'slash' like character like \ but it ends up being a /

With all the user definable characters of the plus chip it should be possible to create a small full bitmap window, the datasheet mention two sets of 96 definable characters but does anyone know how you select between these two sets ? I assume that is why there is (in the original Basic) a SETET and a SETEG command, both types have different attributes.

« Last Edit: June 15, 2011, 12:59:04 AM by gertk » Logged

>>G7000 G7200(P+S) G7400 N60 JET27 VG5000 ZX80 ZX81 ORIC-1 COMX35 Aquarius<<
Rene_G7400
Moderator
I take the Videopac and leave the Canoli!
*****
Posts: 2519



WWW
« Reply #10 on: June 15, 2011, 03:00:46 PM »

With all the user definable characters of the plus chip it should be possible to create a small full bitmap window, the datasheet mention two sets of 96 definable characters but does anyone know how you select between these two sets ? I assume that is why there is (in the original Basic) a SETET and a SETEG command, both types have different attributes.

T= text (alphanumeric) and G = graphic (semi-graphic). For alphanumeric characters bit 7 of the attribute byte is zero, and for semi-graphic characters this bit is one. There are 96 self-definable alphanumeric characters and 96 self-definable semi-graphic characters.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!