News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

GB TETRIS EMULATOR TEMU FOR AMSTRAD CPC 6128(+)

Started by 40Crisis, 21:24, 17 September 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Gryzor

Damn all the files I tried today failed... Is it so hard to find the correct ROM or was I just unlucky?

TotO

Quote from: Gryzor on 16:29, 21 September 20
Damn all the files I tried today failed... Is it so hard to find the correct ROM or was I just unlucky?
Did you add the Amsdos header?
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Gryzor

Yes I did, I read all the instructions here...

But finally... all is well ;) And awesome!!!

40Crisis

#53
Quote from: roudoudou on 09:50, 21 September 20
Hi @40Crisis Can you tell us how the emulator works?
Thank you
GB Hardware emulation is quite easy because I/O is done on the GB through memory registers (not ports).
A few rom traps are needed to render graphics, sound and input.GB Sharp LR35902  code is executed as is  on CPC Z80 because it's a modified Z80 with a few different instructions. 9 extra instructions not present in z80 are needed for emulating tetris.
They are emulated using the eight RST instructions available on the Z80. It takes me time to figure out how to do it without loosing too much speed. This is quite slow but does the job.
Graphics rendering is done on CPC by only displaying changing areas. Graphics are rendered asynchronously when there's enough time after the gameloop rendered at 60Hz. Average measured framerate is about 25 Hz ingame.

40Crisis

Quote from: norecess on 16:24, 21 September 20
Woaahh this reminds me the excitement I got when I discovered Syx/TotO's PacMan emulator few years ago..!

Splendid, I'm sincerely impressed.

Please, release a V2 with some (if not all..) of the improvements from TotO ! :)
Thanks for your nice feedback
I'll try to do my best to include improvements from TotO

SyX

Quote from: norecess on 16:24, 21 September 20
Woaahh this reminds me the excitement I got when I discovered Syx/TotO's PacMan emulator few years ago..!
Merci!!! :) You made my day happy... waiting for a really happy day when you release your next Mega Production ;)

And of course, AMAZING WORK @40Crisis!!!  8) 8) 8)

I know that being Tetris a really famous game and after this wonderful result, this project will get you a lot of acclaim in the community, but you deserve that because along of the years you have brought to the CPC great classic games and I will play and enjoy them until your next project arrive. ¡Muchas Gracias!  ;)


roudoudou

thank you for all explanations  8)
Quote from: 40Crisis on 19:49, 21 September 209 extra instructions not present in z80 are needed for emulating tetris.
They are emulated using the eight RST instructions available on the Z80.
ok so the emulator has to know where is the code and the data, it's not plug'n'play  ;D
with a little rework of the original code using those instructions, we may expect more native power
My pronouns are RASM and ACE

Gryzor

OFF-TOPIC:

@40Crisis : please fix your email address in your profile settings, all notification emails are bouncing back :)

TotO

#58
Here a 4 colours 256x256 (16K) bezel picture. (PNG and BIN)
The areas match with a palette change using the Gate Array interrupts.
May be nice to use this format to allow peoples to provide their own "BEZEL.BIN" file.

CPC palettes:
- 9, 13, 12, 25
- 1, 13, 3, 26

PLUS palettes:
- 333, 777, 896, CDA
- 007, 777, 700, EEE
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

TotO

#59
In example, with the Amstrad CPC and Amstrad Plus palettes and rasters
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Gryzor

Never understood the appeal of running Gameboy have on a Big Screen with marquees until now 😁

Joseman

Hi @40Crisis

This isn't coding this is just MAGIC.

I always thought that porting small games from the gameboy was reasonably feasible on CPC.

I didn't know how and the explanation you give is really magic for my ears.

I have remembered my years with the gameboy with your port and it's exactly the same.

Congratulations!!

P.S. will you release the sourcecode for another people to port other games or do you think on make other ports?

norecess464

#62
@40Crisis  One small request: while CAPS LOCK key may be a good idea on real CPC keyboards, please can you also add another mapping for it (SHIFT, CONTROL..) ? Many people will probably run the game through an emulator, and the CAPS LOCK key is absolutely not convenient for that purpose on PC keyboard.
My personal website: https://norecess.cpcscene.net
My current project is Sonic GX, a remake of Sonic the Hedgehog for the awesome Amstrad GX-4000 game console!

Longshot

@40CrisisYou did work on a very interesting subject.
Bravo for this achievement!  ;)

I am amazed to see that there are no ld (a16),hl and ld hl,(a16) instructions on LR35902 processor.
The replacement for ld (hl-),a and ld a,(hl-) is delicate since they replace instructions that already exist with other opcodes (ld a,(a16)/ld (a16),a)

If I could make a few remarks:

You forgot to remove one ld (hl),a from the routine that patches the memory with bytes, just before running the rom. (thus doubling ld (hl),a)
(a remainder of the copy/paste routine that patches the memory with words)

You don't need to use DI at the begining of your interrupt routine (called in vectorized mode under IM2 mode)
No other interrupt can occur until the ei/ret (reti not needed)

I think you can improve the swap a and swap e instructions, which you simulate with the rst38h instruction by setting the Carry Flag
For swap a (cb 37), I think you can just do rrca/rrca/rrca/rrca
For swap e (cb 33), I think you can just do rrc e/rrc e/rrc e/rrc e
For this latter instruction, which you patch once at 6db0 in the ROM, I think there is a bug:
ld e, a
exx
ex af, af '
ret


instead of
exx
ld e, a
ex af, af '
ret


Can you tell us more about the management of the graphical interface?
Do you have a unique periodic rendering routine for data generated by the GB in its IO space?
Rhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!

40Crisis

#64
Quote from: Longshot on 09:57, 23 September 20
@40CrisisYou did work on a very interesting subject.
Bravo for this achievement!  ;)

It's an honor to have a CPC Legend commenting my project

I am amazed to see that there are no ld (a16),hl and ld hl,(a16) instructions on LR35902 processor.
The replacement for ld (hl-),a and ld a,(hl-) is delicate since they replace instructions that already exist with other opcodes (ld a,(a16)/ld (a16),a)I was aware of this problem and replacement needs to be done in a particular order
If I could make a few remarks:

You forgot to remove one ld (hl),a from the routine that patches the memory with bytes, just before running the rom. (thus doubling ld (hl),a)
(a remainder of the copy/paste routine that patches the memory with words)
You're right copy and paste is not a good habit when coding but so convenient

You don't need to use DI at the begining of your interrupt routine (called in vectorized mode under IM2 mode)
No other interrupt can occur until the ei/ret (reti not needed)Thanks for the info, will try it
I think you can improve the swap a and swap e instructions, which you simulate with the rst38h instruction by setting the Carry Flag
For swap a (cb 37), I think you can just do rrca/rrca/rrca/rrca
For swap e (cb 33), I think you can just do rrc e/rrc e/rrc e/rrc eMuch more clever and efficient that the one I wrote
For this latter instruction, which you patch once at 6db0 in the ROM, I think there is a bug:ld e, a
exx
ex af, af '
ret


instead of
exx
ld e, a
ex af, af '
ret

You're absoluty right about the bug, what a good sight you have

Can you tell us more about the management of the graphical interface?
Do you have a unique periodic rendering routine for data generated by the GB in its IO space?
Yes there's one rendering routine fo background titles and one for the sprites ( splitted in 8 multiple aligned or not)


40Crisis

Quote from: norecess on 12:41, 22 September 20
@40Crisis  One small request: while CAPS LOCK key may be a good idea on real CPC keyboards, please can you also add another mapping for it (SHIFT, CONTROL..) ? Many people will probably run the game through an emulator, and the CAPS LOCK key is absolutely not convenient for that purpose on PC keyboard.
Very good suggestion

LEFT SHIFT will be as TAB and CONTROL the same as CAPS if you agree in the next release.

40Crisis

#66
Quote from: Joseman on 12:33, 22 September 20
Hi @40Crisis

This isn't coding this is just MAGIC.

I always thought that porting small games from the gameboy was reasonably feasible on CPC.

I didn't know how and the explanation you give is really magic for my ears.

I have remembered my years with the gameboy with your port and it's exactly the same.

Congratulations!!

P.S. will you release the sourcecode for another people to port other games or do you think on make other ports?
I don't plan to release source code.
Anyway, I believe the emulator was possible because tetris is a simple game with few things displayed.
In my opinion, the CPC is not powerful enough to emulate GB 4,19MHZ processor plus 60Hz display rendering (background tiles 160x144 plus up to 40 8x8 four color sprites).
To give you an idea the emulator ingame (maximum 12 sprites 8x8 are displayed) has a average speed of 25 fps.

Khomenor


Quote from: Redbug on 15:05, 18 September 20

Ok..
You break the game :(
My port seems so.... a waste of time...


https://www.facebook.com/redbug/videos/10158439917016668/?t=3
Your port is not a waste of time, You made a port, 40crisis made an emulator :)
As I said in Oncle_ced's stream I like your port, not the music. Just not my kind of remix  ;)

Gryzor

Indeed I love both for different reasons...

Longshot

#69
Oups...Better like this to take care of the carry flag... ;D
For swap a (cb 37), rrca/rrca/rrca/rrca/ccf
For swap e (cb 33), rrc e/rrc e/rrc e/rrc e/ccf

In the graphics engine, you can save cpu and code as well.
To calculate the address of the tile
19 usec, 10 bytes
        ld h,0
        ld l,a               
        add hl,hl       
        add hl,hl
        add hl,hl
        add hl,hl
        ld a,#80           
        or h
        ld h,a
You can simplify it by doing ld h,8 instead of ld h,0 and deleting ld a,#80...
But you can also do that
    15 usec, 10 bytes
    ld hl,bonneteau+1
    ld (hl),a
    ld a,#80
    rld
bonneteau ld l,0
    ld h,a

or this
    15 usec, 15 bytes   
    ld h,8
    add a,a
    rl h
    add a,a
    rl h
    add a,a
    rl h
    add a,a
    rl h
    ld l,a

When updating the screen, for each         
         ldi
        ldi
        dec e
        dec e

replace dec e by ld e,b
at the end of one tile, replace         
         exx
        ld d,c
        ld e,b
        inc e
        inc e
        exx


by this       
        exx
        ld d,c
        exx
Rhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!!

40Crisis

Quote from: Longshot on 17:23, 24 September 20
Oups...Better like this to take care of the carry flag... ;D
For swap a (cb 37), rrca/rrca/rrca/rrca/ccf
For swap e (cb 33), rrc e/rrc e/rrc e/rrc e/ccf

In the graphics engine, you can save cpu and code as well.
To calculate the address of the tile
23 usec, 10 bytes
        ld h,0
        ld l,a               
        add hl,hl       
        add hl,hl
        add hl,hl
        add hl,hl
        ld a,#80           
        or h
        ld h,a
You can simplify it by doing ld h,8 instead of ld h,0 and deleting ld a,#80...
But you can also do that
    15 usec, 10 bytes
    ld hl,bonneteau+1
    ld (hl),a
    ld a,#80
    rld
bonneteau ld l,0
    ld h,a

or this
    15 usec, 15 bytes   
    ld h,8
    add a,a
    rl h
    add a,a
    rl h
    add a,a
    rl h
    add a,a
    rl h
    ld l,a

When updating the screen, for each         
         ldi
        ldi
        dec e
        dec e

replace dec e by ld e,b
at the end of one tile, replace         
         exx
        ld d,c
        ld e,b
        inc e
        inc e
        exx


by this       
        exx
        ld d,c
        exx

Master class of z80 programming by Longshot ! Thank you. Optimisations will be included in next update to come

40Crisis

New version 1.1
What's new- added gb inlay  + cpc palette and cpc+ palette from totO: many thanks to him
- emulator can be now run in two flavour:run"temu" for cpcrun'temuplus" for cpc+
- some bug fixes and code optimisation thanks to Longshot
- two new keys left shift and left control same as tab and CAPS LOCK suggested by Norecess
- You can edit main palette for cpc and cpc plus in basic loader see line 210 and more

TotO

#72
Amazing work!!!  8)

Here, some WIP theme for CPC if you can't wait.
Just update the BASIC with the colours codes on the top of your floppy drive hardware values.
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

40Crisis

Quote from: TotO on 16:39, 26 September 20
Re: GB TETRIS EMULATOR TEMU FOR AMSTRAD CPC 6128(+)
« Reply #72 on: Today at 18:39 »

    Like
    Quote
If you intend to customize palette, you will need the CPC hardware value:


reference here: https://www.cpcwiki.eu/index.php/CPC_Palette


vasilisk

#74
Looks much better on real cpc. Sorry for the poor capture. My phone is not good for video recording 50fps. :)



https://youtu.be/fFqsJg7eHus

Powered by SMFPacks Menu Editor Mod