Videopac / Odyssey2 forum

Videopac / Odyssey2 => Hardware => Topic started by: gertk on December 07, 2011, 12:09:25 AM



Title: mbed emulating a ROM cartridge
Post by: gertk on December 07, 2011, 12:09:25 AM
Whoa, it works !

The mbed is emulating a rom cartridge without any extra hardware.
I am running out of address/bank select pins though. The LPCxpresso has extra IO so that will be the better (and cheaper) candidate But still... It works..

On the two (crappy) photo's you can see the mbed connected directly to the cartridge port of a G7000 board and it starts up with the select game screen and Omega Race is running (second photo).
I did fell into the trap of the swapped A6 and A7 lines (A5=M, A6=P and A7=N )

The mbed is running in a rather tight loop just checking if PSEN drops, then reads out the G7000 addressbus and emits a byte from the stored rom image onto the data bus, then waits for PSEN to go high again and releases the databus again. Because of the pin connections on the mbed I have to 'connect' the bits of three IO ports into a single address.

This means it is possible to store a bunch of cartridges on the 2 MB flash of the mbed (or maybe USB stick as the second USB port is still available on the mbed) and create some sort of menu.  


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 07, 2011, 12:09:56 AM
second photo

The mbed is sitting on the LPCxpresso breadboard and is powered by the cartridge port, the only hardware added is a bunch of 100 ohm resistors in series with all the Videopacs address and datalines (just to be safe).


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 07, 2011, 09:54:32 PM
This is the timing of the mbed responding to the 8048 PSEN line (top line is PSEN, bottom line is a data bit).

On the left is a 'zero' bit returned to the 8048 on the rising edge of PSEN, on the right a 'one' bit.

The interrupt latency of the standard mbed routines is what I have to improve, found already some ideas to make that better. If I can get the mbed to handle the rom emulation from within a high priority interrupt it should free the rest of the cycles to do other things like emulating the Voice or the Chess/Basic box...




Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 12, 2011, 10:07:44 PM
Shuffled some port pins around and got interrupts on PSEN working with sufficient little overhead.
Here is Smithereens running, a 4k cart image with bankswitching (I dropped the A10 line as it seems no cartridge uses it)

The blue led at the front is in fact blinking at approx. 10 kHz which I will use as sampling frequency for the voice.
Unfortunately it is not very stable as the interrupts that the PSEN line causes are quite heavy  :) Still it seems I now have enough cycles left to do other things.

Next step is to split out the PSEN and WR interrupt lines to get the voice emulation going. For this I needed Smithereens (NTSC Voice version) and had to implement the bankswitching part.


Title: Re: mbed emulating a ROM cartridge
Post by: Rene_G7400 on December 13, 2011, 12:14:03 AM
(I dropped the A10 line as it seems no cartridge uses it)

Videopac 31 and 40 use A10, and KTAA too.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 13, 2011, 07:47:06 AM
Videopac 31 and 40 use A10, and KTAA too.

Thanks Rene,

In a final design or with the LPCxpresso I can put back A10 quite easily but now I am running out of port pins. The LPC1768 CPU on the mbed has more than enough port pins, but to keep the mbed module within 40 pins some compromises had to be made.  :)
I wanted to use P10 and P11 so I could test the bankswitching and get Smithereens going (although Smithereens would work without P11)

All in all it is quite 'weird' to see the Videopac running without a real ROM  :)

If I can manage to generate an interrupt on the falling and one on the rising edge of PSEN some more cycles could be won. Now the interruptroutine has to wait until the pin goes high again wasting cycles.



Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 13, 2011, 01:08:27 PM
This is the ARM assembler code for the interrupt routine, for any one interested  :)

Code:
my_irq
   
    LDR     R1,=0x2009c040      ; port2
    LDR     R2,[R1,#0x14]       ; get byte value from port
    AND     R2,#0x0000003F      ; save bits for A0-A5
   
    LDR     R1,=0x2009c000;     ; port0
    LDR     R3,[R1,#0x14]       ; get port0 value   
    AND     R3,#0x00078000      ; and of A6-A9
    LSR     R3,#9               ; shift down
    ORR     R2,R3               ; or in bits A6-A9

    LDR     R3,[R1,#0x14]       ; get port0 value
    AND     R3,#0x03800000      ; and off bits A11, P10 and P11
    EOR     R3,#0x03000000      ; invert P10 and P11
    LSR     R3,#13              ; shift to A10,A11 and A12
    ORR     R2,R3               ; or in the bits as A10, A11 and A12
   
    ; insert test for PSEN or WR here
   
    LDR     R3,=testrom         ; address of our rom
    LDRB    R2,[R3,R2]          ; get a byte with calculated offset
    LSL     R2,#4               ; shift up 4 bits (data bus is P0.4-P0.11)
    STR     R2,[R1,#0x14]       ; output the byte

    MOV     R3,#0x00000FF0;     ; output mask
    STR     R3,[R1]             ; set port to output
       
wait_for_psen_high   
    LDR     R3,[R1,#0x14]       ; get port0 value
    TST     R3, #0x00000002     ; and test psen (P0.1)
    BEQ     wait_for_psen_high  ; wait for PSEN to rise again
       
    MOV     R3,#0x00000000      ; input mask
    STR     R3,[R1];            ; set port to input again

    MOV     R3,#0x7fffffff      ;  clear mask
    LDR     R1, =0x4002808C     ;  IO0INTCLR   
    STR     R3,[R1]             ;  clear interrupt flag

    BX      LR                  ; return to caller
    ALIGN                       ; make compiler happy
    END

All these instructions are single cycle (a little bit over 10 ns each)


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 13, 2011, 01:14:31 PM
Are there any cartridges which use external RAM (in the cartridge I mean) ?


Title: Re: mbed emulating a ROM cartridge
Post by: Rene_G7400 on December 13, 2011, 01:52:20 PM
Are there any cartridges which use external RAM (in the cartridge I mean) ?

No. The PCB's of Videopac 31 and 40 are suitable for an extra 6810 chip, but it's not used.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 13, 2011, 06:51:13 PM
No. The PCB's of Videopac 31 and 40 are suitable for an extra 6810 chip, but it's not used.

Ok, so that will make the emulation part a bit simpler :)
The only 'write' things for now will be the Voice and the latches of the Chess and Basic box then.

Thanks again


Title: Re: mbed emulating a ROM cartridge
Post by: Rene_G7400 on December 14, 2011, 10:05:41 AM
The only 'write' things for now will be the Voice and the latches of the Chess and Basic box then.

And the latches of Videopac 55, 58, 59 and 60 and the Service Testcart.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 14, 2011, 01:35:59 PM
And the latches of Videopac 55, 58, 59 and 60 and the Service Testcart.

Do you have address mappings or circuit diagrams of these ?

Yesterday evening I got the write part working, now I must try and create a reasonable sampling frequency or another low priority interrupt to push out the samples created by the sp0256 emulator. I could not find exact timing info of the internals of the sp0256, only know that it runs from an external 3.12 MHz xtal

All of the 'standard' interrupt functions of the mbed IDE are way too slow for this kind of tricks. I also found out some more port pins are available if I omit the second USB port function. The mbed itself has 2 MByte of local storage which should be more than enough for some multicart experiments, the CPU itself has 512k of flash and 64k ram.


I considered doing the Basic module emulation first but then I have to connect the mbed board to a G7400.. The 'naked' G7000 board I use now is easier to access with a scope probe  :) 

The Chess box should be easier as it does not need 'plus' functions and is fully asynchronous to the Videopac (AFAIK it will wait indefinetely until the box answers) and generates no realtime output.
(Thinking of this: it would be nice to make a 'plus frontend' with better graphics for the chess module..)




Title: Re: mbed emulating a ROM cartridge
Post by: Rene_G7400 on December 15, 2011, 11:59:29 AM
Do you have address mappings or circuit diagrams of these ?

This is the circuit of Videopac 55, 58, 59 and 60.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 15, 2011, 01:15:25 PM
Thanks Rene,

I already notice that the memory mapping must be 'dynamic' for different cartridge emulations but that is no problem.
As you can see the interrupt routines are very small so I can create several routines for different types of cartridges and make some function to recognize the cartridge rom image, by size, checksum or name.

Another thing I must think about is how to select a rom image, load it up into the internal ram of the mbed and get the Videopac to execute it (other than pressing 'reset') During the load from the flash storage the interrupts are disabled so the 8048 will crash if it is executing code from the emulator, maybe I can force the 8048 to keep executing NOP's until the mbed is ready again.

 


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 19, 2011, 12:58:20 AM
First sounds came out with Smithereens: "Action", "Come On You Turkey" and such, hilarious!
Alas it crashes the rom emulator but still, progress...
I guess I have a IO port conflict as I am writing/reading from the IO ports from both outside and inside the interrupts.

I used a TDA2822(M) as an amplifier (in bridge mode for simplicity) to drive a small speaker from a defunct TomTom but it makes a hell of a lot of noise  :D  It also picks up GSM interference from over 2 m away...


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on January 06, 2012, 08:10:41 AM
The emulation part is now working ok, including the Voice emulation.

Steps to take:

  • identify the cartridge roms and load them correctly from the mbed flash space into mbed ram, which chunk goes where, some cartridges use A10 some don't
  • create some kind of menu (Videopac software)
  • try to 'catch' the Videopac CPU after loading a cartridge into mbed ram and start the game, preferably without reset
  • create a cartridge PCB design for mbed or LPC1768
  • update the emulator so it does Chess and Basic module emulation (that is all just software now)


Title: Re: mbed emulating a ROM cartridge
Post by: manopac on January 06, 2012, 10:58:37 AM
can't wait for it :-)


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on January 29, 2012, 10:54:58 PM
Well, ok this should officially be in 'programming'  I guess..

I now have a usable screen output on the Videopac which can be written into from the mbed. It is based on Rene's original code to rewrite the quads multiple times.

My Videopac code fills the quads from rom space (characters at 0x600 and attributes 0x700) and since the rom can be written into from the mbed side it is now sort of a text output screen which can be controlled by the mbed.

The screen is now 7 lines of 16 characters with color attributes for each character.
My idea is to use this as a menu screen for the Videopac rom images on the mbed's internal storage of which you can then make a selection and it will be loaded into the rom emulator.

I could not manage 128 characters like Rene did because of my routine taking more cycles but still, 7 lines is not bad either. Also it is at the moment PAL only, have not tried it on a Odyssey2 yet. (O2EM displays it the same whether I use the -euro switch or not)

A sneak peak to how the display looks like (after hours and hours of trying to get the timing right):


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on January 30, 2012, 08:22:15 PM
Just to show how tight the timing is: In the picture below the white bars represent the time spent in the routine rewriting the quads. If anyone can think of a faster way to write the data for four quads directly from rom...


Title: Re: mbed emulating a ROM cartridge
Post by: TedFoolery on January 31, 2012, 03:45:59 PM
I wanted to try something last night, but didn't have time.

How many lines were you looking to achieve? If you want a 16x8 display like Rene, you could pack all the data in 0x600 alone. You only really need 2 bytes per character (char/color - bytes 2 & 3), since the X & Y (bytes 0 & 1) are predetermined.
So 8 lines * 16 columns * 2 bytes = 256

Pulling data from 1 page should be quicker than switching between multiple pages.

I think I can get this to work on an NTSC machine. Hopefully I can find some time tonight to tinker around.

...And the goal is to get all the characters inside the large grid, right?


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on January 31, 2012, 06:35:12 PM
I wanted to try something last night, but didn't have time.
How many lines were you looking to achieve? If you want a 16x8 display like Rene, you could pack all the data in 0x600 alone. You only really need 2 bytes per character (char/color - bytes 2 & 3), since the X & Y (bytes 0 & 1) are predetermined.
So 8 lines * 16 columns * 2 bytes = 256

Hi Ted,

If I put all 256 bytes in page 0x600 where would I leave the code to access it with movp ? AFAIk the code has to be on the same page ?

Quote
Pulling data from 1 page should be quicker than switching between multiple pages.

My code jumps from a piece of code on page 0x600 (with 127 bytes characterdata at the beginning of the page) to a piece of code in page 0x700 (with the 127 bytes atttribute data at the beginning). But with 7 lines it might be possible to condense it into a single page. ('attribute data' is the ninth bit and the color) Still the loading of the A register (for movp A,@A) from my pointer register is an extra byte/set of cycles.

Code:
mov R0,#VDC_QUADn  ; select appropriate quad register n
mov A,R5                   ; get pointer (offset from page start) in A
movp A,@A                ; read a byte from 'rom'
movx @R0,A              ; move into VDC register
inc R5                        ; increment pointer
.... ad nauseum for two registers per quad and all quads..
In my first code attempt I jumped from page to page each time for each character per quad in a subroutine but then I thought of 'unrolling the loop' by putting all character writes in one page and all attribute writes in the other (one after eachother) so I only needed to jump once to the other page.

Quote
I think I can get this to work on an NTSC machine. Hopefully I can find some time tonight to tinker around.
...And the goal is to get all the characters inside the large grid, right?

Yes that would be nice but I have disabled the inner lines so it is still inside the large square  :)
I am planning to use the characters also, I think it is possible to squeeze in a row of 8 characters before (or after) the quads. And then I have the sprites for a multicolor cursor or such.  :D

I will place my quad fill code here below if Rene does not mind (I used his code as a guideline)  :)


Title: Re: mbed emulating a ROM cartridge
Post by: TedFoolery on January 31, 2012, 08:46:14 PM
There's a command movp3 A,@A  which works like movp, but pulls data specifically from page 3, no matter what page you are currently in (I guess that would mean you'd need to put the data in 0x0700, not 0x0600). You then wouldn't need to put any retrieval code in page 3.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 01, 2012, 07:36:12 AM
There's a command movp3 A,@A  which works like movp, but pulls data specifically from page 3, no matter what page you are currently in (I guess that would mean you'd need to put the data in 0x0700, not 0x0600). You then wouldn't need to put any retrieval code in page 3.

I stumbled on that command too  :) When I read it in the 8048 manual I first interpreted it as reading from a page where A10 and A11 where high (meaning 0xC00-0xCFF which would be nice!) but alas it means A8 and A9 are high so it really reads from 'page 3' meaning 0x300-0x3ff .. so that is internal rom of the CPU so it is of no use for my routine.

Here is a small excerpt of my code:

Code:

.org 0x600 ; page boundary
romdata:
;
; include externally generated character codes
;
.include "characters.asm"

; copy character byte
; quad 0 is interleaved with quad 1 and quad 2 is interleaved with quad 3
;
docopy:
mov r0,#0x42 ; pointer to quad '0 0'
mov a,r5 ; get pointer
movp a,@a ; get character byte
movx @r0,a ; store
inc r5

mov r0,#0x52 ; pointer to quad '1 0'
mov a,r5 ; get pointer
movp a,@a ; get character byte
movx @r0,a ; store
inc r5



mov r0,#0x46 ; pointer to quad '0 1'
mov a,r5 ; get pointer
movp a,@a ; get character byte
movx @r0,a ; store
inc r5

mov r0,#0x56 ; pointer to quad '1 1'
mov a,r5 ; get pointer
movp a,@a ; get character byte
movx @r0,a ; store
inc r5
....
        jmp docopy2

; attribute data is preset to be white
;        16 characters on a single row (4 quads)
.org 0x700 ; next page boundary
;
; include externally generated attribute codes
;
.include "attributes.asm"
;
; copy attribute (color and bit 9)

docopy2:
mov r0,#0x43 ; pointer to quad '0 0'
mov a,r5 ; get pointer
add a,#-15 ; adjust pointer back
mov r5,a ; and store
movp a,@a ; get attribute byte
movx @r0,a ; store
inc r5

mov r0,#0x53 ; pointer to quad '1 0'
mov a,r5 ; get pointer
movp a,@a ; get attribute byte
movx @r0,a ; store
inc r5

mov r0,#0x47 ; pointer to quad '0 1'
mov a,r5 ; get pointer
movp a,@a ; get attribute byte
movx @r0,a ; store
inc r5

mov r0,#0x57 ; pointer to quad '1 1'
mov a,r5 ; get pointer
movp a,@a ; get attribute byte
movx @r0,a ; store
inc r5
.....
        jmp copydone     ; jump back to main program

Because of the repetetive character I did not show all lines but you get the idea.
I could shave of a few cycles by interleaving the character and attribute data.This means one  mov R0,#nn can be replaced by inc R0 which should be a bit faster.


Title: Re: mbed emulating a ROM cartridge
Post by: Rene_G7400 on February 01, 2012, 09:45:34 AM
I will place my quad fill code here below if Rene does not mind (I used his code as a guideline)  :)

I don't mind.


Title: Re: mbed emulating a ROM cartridge
Post by: TedFoolery on February 01, 2012, 04:43:00 PM
gertk,
Sorry, you're right about the movp3. (forgive me. It's been a while)

And I passed out last night, so I didn't get to try anything. But this is what I was going to try: It's more complex, but you could do a two step process:
1. Somewhere in the middle of a line, you can get the interrupt to move data from ROM into EXRAM. The data can be stored in multiple pages, but interleave it when writing to EXRAM. Since you are not updating the screen, you don't have to turn off the gfx.
2. Now, when the line of text is complete, turn off the gfx and retrieve data from EXRAM and write VDC. This should be a bit faster than reading from ROM. (there is a special setting that enables Ext reads from RAM and Ext writes to VDC)

This is cumbersome, but I think you can shave off a few cycles from the VDC writes.

The VDC writing would be something like this. This is untested.
Code:
mov r0,#0x42 ; pointer to quad '0 0'
mov r1,#0xff ; pointer to exram

orl p1,#0x7c                      ; enable exram reads, vdc writes
anl p1,#0xe7

movx a,@r1 ; get character byte
movx @r0,a ; store
inc r0
dec r1

movx a,@r1 ; get color byte
movx @r0,a ; store
inc r0
inc r0
inc r0
dec r1

movx a,@r1 ; get character byte
movx @r0,a ; store
inc r0
dec r1

..... Insert other read/writes

movx a,@r1 ; get character byte
movx @r0,a ; store
inc r0
dec r1

movx a,@r1 ; get color byte
movx @r0,a ; store
jmp


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 03, 2012, 10:20:19 PM
This weekend I will give it a try and mix both methods.

Another weird thing I thought of: the bit which sets 'copy' mode, can it be 'abused' to read from EXRAM and write to the VDC at the same time (both devices selected) I did not check the schematics for this yet.

I used a read with automatic write once for a microcontroller experiment which drove a controllerless 320x240 monochrome LCD display. I connected the 4 bits of the LCD screens high speed bus to a multiplexer which was connected to the RAM chip's 8 bit data bus. By 'dummy' reading an address from ram, the data was clocked into the LCD simultaneously, on each read the multiplexer was flipped to put the other nibble onto the LCD's bus (I did need to read the same byte twice). This way the microcontroller could still determine what had to be sent to the display but there was no need for reading and writing and multiplexing by software. It went from 15 frames per second to over 150 and I had to slow it down back to 70 which was the manufacturers recommended frame rate  :)


Title: Re: mbed emulating a ROM cartridge
Post by: manopac on February 03, 2012, 11:04:22 PM
Another weird thing I thought of: the bit which sets 'copy' mode, can it be 'abused' to read from EXRAM and write to the VDC at the same time (both devices selected) I did not check the schematics for this yet.

not sure I interpret your question correctly, but yes - thats exactly what the copy mode is for - to copy data fast from EXRAM to VDC ... so its not really abuse ;-)


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 05, 2012, 11:21:46 AM
not sure I interpret your question correctly, but yes - thats exactly what the copy mode is for - to copy data fast from EXRAM to VDC ... so its not really abuse ;-)

I meant accessing them in 'one stroke' so the read operation from the EXRAM triggers the write operation into the VDC.
If I'd place the data to be written in the same offsets in EXRAM as they are in the VDC you could address them simultaneously.
But since the /WR line is connected directly to the CPU I guess that is not possible (on some microcontrollers you can drive the WR and RD lines just like any other port pin)

Thinking of it: using the same offsets in EXRAM as in the VDC decreases the number of instructions, you'd need only one pointer.. Hmmm...   :)



Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 05, 2012, 02:37:02 PM
Done it.. all 8 lines present using EXRAM in copy mode and filling the EXRAM from 'ROM'.
In the picture below you can see the timing (the white bars are the time spent in copying the quad data from EXRAM)
By using a single pointer it just fits in between the quads vertically..\
The mbed already fills the 'rom' space with a list of filenames found on its internal storage.

Next step is to make the mbed respond to joystick and/or keyboard commands from the Videopac.
I think I will use the already present emulated 'voice command register' as transfer medium to get key or joystick codes to the mbed side and handshake through the T0 line.



Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 05, 2012, 02:48:14 PM
A small piece of the code used:

Code:
..................
;
; wait for start of line 'r6'
;
mov r0,#vdc_scanline ; pointer to VDC scanline register
mov r1,#vdc_scanrow ; pointer to VDC scanrow register
;
; wait for scanline to arrive at next Y (r6) position
;
chky:
movx a,@r1 ; read scanrow
movx a,@r0 ; read scanline
add a,r6           ; add R6 (compare to -R6)
jnc chky           ; if not reached, just wait


; --------------------------------------------------------------------------------
; disable VDC output and set the new Y positions for all 4 quads
; this routine needs to be as short as possible
;
mov r1,#vdc_control ; preset r1 to vdc control
mov a,#0x0a ; set grid on and strobe XY but disable display
movx @r1,a ; store in vdc control

mov r0,#vdc_color ; timing debug code
mov a,#0x3a
movx @r0,a

mov a,r4 ; get Y pos for this line of quads
mov r0,#vdc_quad0_ypos ; store in quad 0 y position
movx @r0,a
mov r0,#vdc_quad1_ypos ; store in quad 1 y position
movx @r0,a
mov r0,#vdc_quad2_ypos ; store in quad 2 y position
movx @r0,a
mov r0,#vdc_quad3_ypos ; store in quad 3 y position
movx @r0,a

jmp exram2vdc ; do copy from exram to vdc
copydone:
mov r0,#vdc_color ; timing debug code
mov a,#0x02
movx @r0,a

mov a,#0x2a ; set FOREGROUND, GRID and STROBE XY bits
movx @r1,a ; store in vdc control enable display
; --------------------------------------------------------------------------------

mov a,r4 ; get Y pos for this line of quads
add a,#LINEDISTANCE ; add LINEDISTANCE
mov r4,a ; store back in R4

mov a,r6 ; advance R6 with LINEDISTANCE lines
add a,#-LINEDISTANCE ; store back in R6
mov r6,a

djnz r3,doupdate ; until all screen lines done

jmp mainloop ; endless loop...

;
; copy EXRAM data to VDC in copy mode
; the data is already set at VDC offsets
exram2vdc:
;
; enable 'copy' mode
;
orl p1,#0x7c            ; enable exram reads, vdc writes
anl p1,#0xe7

mov r0,#0x42 ; pointer to quad '0 0' character data
movx a,@r0 ; read from EXRAM
movx @r0,a ; write to VDC
inc r0 ; increment pointer to attribute data
movx a,@r0 ; read from EXRAM
movx @r0,a ; write to VDC

mov r0,#0x52 ; pointer to quad '1 0'
movx a,@r0 ; read from EXRAM
movx @r0,a ; write to VDC
inc r0 ; increment pointer to attribute data
movx a,@r0 ; read from EXRAM
movx @r0,a ; write to VDC
.....
;
; disable 'copy' mode and enable VDC access
;
orl p1,#0xbc            ; enable VDC access
anl p1,#0xb7

jmp copydone ; jump is faster than return


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 05, 2012, 06:07:00 PM
Another step done: the Videopac sends key and/or joystick commands to the mbed en it responds too  :)

Code:

     call vdcenable ; enable VDC
call waitvsync ; wait for vblank

jt0 nomov ; mbed has not cleared T0 so no new data can be sent

dis i ; disable further interrupts
sel rb0 ; select register bank 0
in a,p1 ; get port1 setting
mov r6,a ; save in R6
orl p1,#0xbc ; enable luminance, disable COPYMODE, NC, EXRAM, VDC and KEYBOARD
anl p1,#0xbb ; enable KEYBOARD

mov r0,#0xf0 ; preset R0
mov r2,#0x08 ; and R2
call readkey_plus ; scan keyboard
jb7 nokey ; skip if no key pressed

;
; send keyboard code to the mbed side
;
call extramenable ; enable EXRAM

orl a,#0x80 ; set bit 7
mov r0,a ; make pointer
mov a,#0x00 ; set all data bits low
movx @r0,a ; write keyboard data

call vdcenable ; enable VDC
mov a,#0x56 ; play sound 0x56
call playsound ; do it
jmp startdisplay ; show it

nokey:
mov r0,#joystickdelay ; pointer to joystick delay
mov a,@r0 ; get value
jnz nojoy ; non zero ? then skip

mov r1,#0x00 ; select joystick 0
call getjoystick ; call bios
mov a,r1 ; get bit values
cpl a ; invert
jz nomov ; if non zero stick is not moved

;
; send joystick code to the mbed side
;
call extramenable ; enable EXRAM

orl a,#0x80 ; set bit 7
mov r0,a ; make pointer
mov a,#0xff ; set all data bits high
movx @r0,a ; write joystickdata

call vdcenable ; enable VDC
mov a,#0x66 ; play sound 0x66
call playsound ; do it

mov r0,#joystickdelay ; point to joystickdelay
mov a,#0x07 ; reset to 7 (vblanks)
nojoy:
dec a ; decrement joystick delay
mov @r0,a ; store back
nomov:

Data bit 5 is used for the voice as reset bit but it is now used as a selection bit between keyboard and joystick data.


Next step: load the selected rom into the emulator and start it up..

Another idea: using the '?' key could make a screen appear which has a (small) description of the selected game. This could be based on the CRC of the rom file.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 06, 2012, 08:12:46 PM
Testing the scrolling function with joystick and keyboard

YouTube: http://www.youtube.com/watch?v=HqzYRxexpx0


Title: Re: mbed emulating a ROM cartridge
Post by: lordbubsy on February 17, 2012, 07:51:00 PM
Quote
We should continue this further in the mbed rom emu thread 

So far I only tested it with the mbed. I am sure the new mbed with the lightweight CPU (Cortex M0) will be too slow (it is also only 10 Euros cheaper than a 'real' mbed). The LPCxpresso and LPCmini both lack the 2MB flash storage so you will have to program some roms in the 512k of onboard CPU flashrom (the mbed's CPU has 512k of internal flash where it downloads the latest .bin file found on the 2MB of USB storage) The advantage of the LPCxpresso is that it has a lot more port pins available and (micro)SD card storage would be easy to add. With the mbed all external port pins are occupied.
OK, I hope this is the right thread.

Sorry for the late response, meanwhile I found:
http://www.watterott.com/de/LPC1769-LPCXpresso
23,80 (+3,50 shipping)

But I?ll wait till you finished your proto, it?s very exiting!
Will hard- and software be open source?




Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 17, 2012, 09:42:13 PM
Yes the LPCxpresso is more pleasingly priced than the mbed but also lacks some features (onboard 2 MB flash rom, USB debug port and ethernet interface). My testboard is officially for the LPCxpresso so it has more IO pins available but the programming environment of the mbed is much easier to use. I do not like IDE?s: they restrict me too much  :) Still, once the mbed code has been compiled to a .bin file it can be easily transferred to the LPCxpresso.

So far my mbed code is not public, I have searched for something similar and could not find anything so it is quite 'unique' I guess. Also the Voice emulation part has some limitations concerning rom contents.
The Videopac code I have no problem with sharing, the first steps have been done by Rene, I only refined the code with some helpful hints from Ted.  Without the mbed part it is not very useful as it just displays the same 'rom' contents over and over again on the screen. The mbed can change that 'rom' contents when needed resulting in an 'instant change of display' on the Videopac side.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 21, 2012, 07:00:20 PM
Small update:

I will go ahead with the LPCxpresso instead of the mbed for the cartridge prototype, with a bit of luck I can manage to take it with me to Apeldoorn to demonstrate it live. The storage will then be on (micro)SD card instead of the 2MB flash which will give even more possibilities. Furthermore I can optimize the data and address connections and calculations with the LPCxpresso because of it having more adjacent port pins available.


Title: Re: mbed emulating a ROM cartridge
Post by: lordbubsy on February 21, 2012, 10:41:21 PM
Quote
So far my mbed code is not public, I have searched for something similar and could not find anything so it is quite 'unique' I guess. Also the Voice emulation part has some limitations concerning rom contents.
The Videopac code I have no problem with sharing, the first steps have been done by Rene, I only refined the code with some helpful hints from Ted.  Without the mbed part it is not very useful as it just displays the same 'rom' contents over and over again on the screen. The mbed can change that 'rom' contents when needed resulting in an 'instant change of display' on the Videopac side.
Thanks for the info.
I finished my G7000 mods and cleaning, :) and enjoyed Satellite Attack on a SONY Trinitron TV for quite a while now.
With a homemade Arcade Joystick ( www.arcadeshop.de/index.php?language=en ) the feeling is even better!

Quote
I will go ahead with the LPCxpresso instead of the mbed
Sounds really great!

Nevertheless I?ll try to modify a cartridge with a 27C080 EPROM and try to address the different games (2k, 4k, 8k) with an AVR.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 26, 2012, 08:06:58 PM
And it fits inside the cartridge.

By separating the programming part and the controller part the LPCxpresso fits nicely inside a cartridge. Now the microSD card socket needs to be placed somewhere convenient and the audio output has to have an outside connection and the prototype can be tested on several machines.


Title: Re: mbed emulating a ROM cartridge
Post by: manopac on February 26, 2012, 10:43:29 PM
cool - how much longer for the production run ?  8)


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 27, 2012, 07:26:06 AM
Has anyone made an Eagle library for a Videopac cartridge ?


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 28, 2012, 07:27:02 AM
Hmm.. seems the programming part also powers the CPU part with 3.3 Volts, so I need to install a 3.3V regulator to get it going   :)


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on February 29, 2012, 10:34:54 PM
Regulator installed, first game from internal ROM finally runs.. Even standalone without the programming part.  :)
I falsely assumed that after reset the ports were initialized as inputs which they were not, some hours lost in debugging that one...
Next step: SD card connection, first get some sleep.... :o


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on March 01, 2012, 10:13:53 PM
Phew.. (micro)SD card is working also, I used the supplied microSD to SD adapter as cardreader on the proto cartridge ( I simply glued it at the top of the front of the cartridge. I even managed to squeeze in a 3.5mm stereo jack for the audio output of The Voice.

Next step: the reset circuit. This must deliver a short reset pulse to the mbed/lpcxpresso when the reset button of the Videopac is pressed longer than 1 second (aka no bus activity for longer than 1 second since there is no reset line on the cartridge port) The mbed/lpcxpresso needs to restart already after pressing the reset button so it can load in the menu from the sdcard and be ready when the 8048 of the Videopac starts up again.

For now, I plugged the cart into the N60 and it is running some games already from the microSD card and it looks great!

Wit a bit of luck it will be 'ready enough' to take it to Apeldoorn.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on March 01, 2012, 10:32:11 PM
some more pics..


Title: Re: mbed emulating a ROM cartridge
Post by: manopac on March 01, 2012, 10:53:27 PM
so cool !! can I be the first one to order one once they are available ?  8)


Title: Re: mbed emulating a ROM cartridge
Post by: VideopacBelgium on March 02, 2012, 12:07:02 AM
Great work !!!
Can I be the 2nd one to order one cart?  :-*


Title: Re: mbed emulating a ROM cartridge
Post by: Janzl on March 02, 2012, 10:11:15 AM
Shit! Now I have to go to Apeldoorn.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on March 02, 2012, 12:56:54 PM
Do not worry, only the proto is going to Apeldoorn but maybe we can discuss some small production batch.
Rene are you going to Apeldoorn too?


Title: Re: mbed emulating a ROM cartridge
Post by: Seob on March 02, 2012, 02:51:28 PM
Shit! Now I have to go to Apeldoorn.
I see you in Apeldoorn then. Will be there between 10.00 and 14.00.


Title: Re: mbed emulating a ROM cartridge
Post by: manopac on March 02, 2012, 08:37:36 PM
btw: any chance to also include C7420 emulation in the cartridge?


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on March 03, 2012, 12:06:59 AM
btw: any chance to also include C7420 emulation in the cartridge?

It is on the list along with Chess. The code is already available from my earlier C7420 emulator. Basic program storage will be on SD card of course. The software emulation of the latches needs some rework.

By using the LPCxpresso I got even more cycles available since I could connect the address and data bus on adjacent port pins instead of having to combine them from three different IO ports.
From every 2.5 usec cycle of the 8048 CPU I have about 1.5 usec available for the mbed/lpc so it leaves enough time to do Z80 emulation. Whenever the 8048 CPU is reading from internal rom the  mbed/lpc is running full speed.
For now I will concentrate on getting the reset circuit ready for Apeldoorn, menu program (Videopac code) is a very early rough version, Voice emulation works for 95% (the 5% being an odd timing problem resulting in sounds being buffered and played back too late, something to do with the reset bit) but all of this is software and not hardware.


Title: Re: mbed emulating a ROM cartridge
Post by: Seob on March 04, 2012, 11:11:04 PM
Gertk showed his cart on one of the few running systems in the place, due to a shortage on power outlets. I was very impressed by the demo. Amazing what one can build and squeeze inside that tiny videopac cartridge, and still have a bit of room for spare.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on March 06, 2012, 10:18:18 PM
Another small succes:

I could not get the Voice timing quite right and there was no way I could use another interrupt without crashing the rom emulator.
But then I found another neat feature of the mbed/LPC's CPU: the System Timer. It is basically a free running counter with a reload option on crossing zero. Normally it is used to create a 'System Tick' for multitasking purposes but I used it to setup a 10 kHz reference for the audio sample output. By simply waiting until the reload flag gets set I have a strict timing offset for the samples without using interrupts.

Now even Crazy Chase sounds OK (Janzl knows how it sounded at the demo... It was slooooowwww... )
Nimble Numbers and Acrobats sound a lot better too..


Title: Re: mbed emulating a ROM cartridge
Post by: Seob on March 06, 2012, 11:16:17 PM
And no more missing sounds when playing Smithereens?


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on March 07, 2012, 07:26:13 PM
And no more missing sounds when playing Smithereens?

Naah, almost  :) Still don't know what is going on there exactly, if I change just some non-trivial things in the testloop of the reset bit it changes behavior already so my guess is that the command and reset bit values are getting cached or optimized in some way.


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on March 27, 2012, 09:46:14 PM
Another 'small' improvement:

The LPCxpresso has a single LED onboard but it is connected to P0_22 and that was a pin I used to read the Videopac's bankswitching output P11.

On the G7000 and G7200 it resulted in some visual instability and on screen menu corruption. Seems the LED (with 2k resistor) pulls the line down to much and it sometimes registers as '0' when it should be '1'. By shuffling some pins around (luckily the LPCxpresso has some left) this problem is now gone too. Another step in the right direction.


Title: Re: mbed emulating a ROM cartridge
Post by: Seob on December 30, 2014, 02:39:30 PM
What is the status of this project gertk?


Title: Re: mbed emulating a ROM cartridge
Post by: gertk on December 30, 2014, 07:00:19 PM
The status is 'dormant'  :) Lately I got a new small ARM CPU to play with and will see if it is up to the job to be used in the emulator (it is the STM32F103 btw) The chip is cheap and even when presoldered to a tiny board it is just a few dollars.

Biggest problem is time and too much things on my mind and hands...