This article pretty much confirms what I suspected, but the author explains it pretty well.
The only thing really missing is how the "magic number" was derived to minimize the error.
This is just speculation on my part, but I see two potential approaches.
The first would be to pick some mid point value that reduces the maximum error for any legal number (within the range of floating point numbers).
The second would be to pick a value that is the mid point for the most common values a program uses, thus minimizing the error for that program more than for any value.
The first would be easy to calculate, the 2nd would require a lot of number logging & crunching.
https://betterexplained.com/articles/understanding-quakes-fast-inverse-square-root/
My on again off again blog about whatever computer related hobby projects I happen to be working on at the moment.
Wednesday, August 26, 2020
Article: Understanding Quake's Fast Inverse Square Root
Monday, March 9, 2020
A little blast from my past
Back in the 80s I was a partner in and vice president of a software business called Designing Minds, Inc.
Here are a few of the programs we produced. All of these are based on my runtime library, as was the Talking Storybook series, yet I somehow didn't get my name on any of the Copyrights. Gee, why did I ever leave?
Link
I was also president, and a partner in an Amiga hardware company.
Here is one of the Amiga drives we made:
Link
Here are a few of the programs we produced. All of these are based on my runtime library, as was the Talking Storybook series, yet I somehow didn't get my name on any of the Copyrights. Gee, why did I ever leave?
Link
I was also president, and a partner in an Amiga hardware company.
Here is one of the Amiga drives we made:
Link
Monday, March 2, 2020
MC-10 Memory map
This is the MC-10 memory map copied from the service manual, but with a few minor changes.
The address decoding inside the MC-10 is "minimal", so the Keyboard/VDG I/O responds over a full 16K area, but internal address decoding can be disabled by external expansion devices.
Programmer's should only use the top of that address range to access that hardware.
The MC-10 only includes 4K of RAM internally, but hi-res 256x192 2 color (RG6), and 128x192 4 color (CG6) modes require 6K. The 6847 VDG's buss is isolated from the expansion connector on the back of the machine, and the top address line isn't even connected, so you can't just plug in a RAM expansion to use hi-res modes. The hardware mod was published in a CoCo magazine shortly after the machine was released, but I'll have to look up what magazine. (Color Computer Magazine maybe?)
Making matters worse, the ROM places BASIC system variables, and interrupt vectors in the upper part of the internal 4K of RAM, so to use hi-res graphics you need a new BASIC, or to disable the ROMs. I've been working on a new ROM, so this is trivial for emulators.
MC-10 Memory map from the service manual
Hex Address
C000 - FFFF 16K ROM (only upper 8K used)
9000 - BFFF 16K I/O Slot (Keyboard, VDG control, and sound)
4000 - 8FFF 16K RAM (4K - 20K used) (video starts at $4000)
0100 - 3FFF Not Used
0080 - 00FF RAM internal to the 6803
0015 - 007F Not Used
0014 RAM Control Register
0013 Not Used
0012 Not Used
0011 Not Used
0010 Not Used
000F Port 3 Control and Status Register
000E Input Capture Register (low byte)
000D Input Capture Register (high byte)
000C Output Compare Register (low byte)
000B Output Compare Register (high byte)
000A Counter (low byte)
0009 Counter (high byte)
0008 Timer Control and Status Register
0007 Not Used
0006 Not Used
0005 Not Used
0004 Not Used
0003 Miscellaneous I/O Data Register
0002 Keyboard Output Lines
0001 Data Direction Register for miscellaneous I/O
0000 Data Direction Register for keyboard lines
The address decoding inside the MC-10 is "minimal", so the Keyboard/VDG I/O responds over a full 16K area, but internal address decoding can be disabled by external expansion devices.
Programmer's should only use the top of that address range to access that hardware.
The MC-10 only includes 4K of RAM internally, but hi-res 256x192 2 color (RG6), and 128x192 4 color (CG6) modes require 6K. The 6847 VDG's buss is isolated from the expansion connector on the back of the machine, and the top address line isn't even connected, so you can't just plug in a RAM expansion to use hi-res modes. The hardware mod was published in a CoCo magazine shortly after the machine was released, but I'll have to look up what magazine. (Color Computer Magazine maybe?)
Making matters worse, the ROM places BASIC system variables, and interrupt vectors in the upper part of the internal 4K of RAM, so to use hi-res graphics you need a new BASIC, or to disable the ROMs. I've been working on a new ROM, so this is trivial for emulators.
MC-10 Memory map from the service manual
Hex Address
C000 - FFFF 16K ROM (only upper 8K used)
9000 - BFFF 16K I/O Slot (Keyboard, VDG control, and sound)
4000 - 8FFF 16K RAM (4K - 20K used) (video starts at $4000)
0100 - 3FFF Not Used
0080 - 00FF RAM internal to the 6803
0015 - 007F Not Used
0014 RAM Control Register
0013 Not Used
0012 Not Used
0011 Not Used
0010 Not Used
000F Port 3 Control and Status Register
000E Input Capture Register (low byte)
000D Input Capture Register (high byte)
000C Output Compare Register (low byte)
000B Output Compare Register (high byte)
000A Counter (low byte)
0009 Counter (high byte)
0008 Timer Control and Status Register
0007 Not Used
0006 Not Used
0005 Not Used
0004 Not Used
0003 Miscellaneous I/O Data Register
0002 Keyboard Output Lines
0001 Data Direction Register for miscellaneous I/O
0000 Data Direction Register for keyboard lines
Nearing completion of the 6502 to 6803 AGD runtime code
As the title indicates, the runtime library code is almost complete. If I had just focused on working on the translation, this would have been done some time ago. but I hope to finish this today. Then I can look at the compiler.
There are some questions with the code that will require looking at the original Z80 code. Why did they do this, why didn't they do that... not sure if the 6502 programmer lacked experience, if I have outdated code, or whatever, there's just some odd looking stuff in the code.
There are sure to be some mistakes in the translation. At the very least, the Z80 & 6502 store 16 bit variables in little endian format, and the 6803 uses big endian. I'm assuming big endian for the translation, which may cause some problems. There may also be a few times where I tried to optimize the code, and I shouldn't have. Likewise, there's probably room for more optimizations where I wasn't sure if they are okay.
Before anyone gets too excited, just remember this requires the internal RAM mod that lets you use hi-res RG6 mode (PMODE 4), and a new ROM or external RAM expansion that lets you disable the internal ROM. The only RAM expansion that lets you disable the ROM is the MCX-128, but I'm not sure that has a memory map setting compatible with the internal RAM upgrade. This should work with an emulator though, and we can worry about the hardware issues later.
There are some questions with the code that will require looking at the original Z80 code. Why did they do this, why didn't they do that... not sure if the 6502 programmer lacked experience, if I have outdated code, or whatever, there's just some odd looking stuff in the code.
There are sure to be some mistakes in the translation. At the very least, the Z80 & 6502 store 16 bit variables in little endian format, and the 6803 uses big endian. I'm assuming big endian for the translation, which may cause some problems. There may also be a few times where I tried to optimize the code, and I shouldn't have. Likewise, there's probably room for more optimizations where I wasn't sure if they are okay.
Before anyone gets too excited, just remember this requires the internal RAM mod that lets you use hi-res RG6 mode (PMODE 4), and a new ROM or external RAM expansion that lets you disable the internal ROM. The only RAM expansion that lets you disable the ROM is the MCX-128, but I'm not sure that has a memory map setting compatible with the internal RAM upgrade. This should work with an emulator though, and we can worry about the hardware issues later.
Saturday, February 29, 2020
code update
The egregious 6502 vs 6803 code comparison has been updated. Yup, I was tired. The 6803 code should be okay now. While fixing the 6803 code, I also noticed the 6502 code looked like it could be improved.
The 6502 code from the shrapnel routine looks like it can be optimized as shown below. Instead of incrementing z80_hl for every byte, use different y offsets, and then update z80_hl once. The comparison is a little less lopsided with this change.
;----------------------------------------------------
; Explosion shrapnel.
;----------------------------------------------------
shrap:
ldy #1
lda (z80_ix),y ; get the angle.
clc
adc #<shrsin ; shrapnel sine table.
sta z80_l
lda #>shrsin
adc #0
sta z80_h
ldy #0
lda (z80_hl),y ; fetch value from table.
sta z80_e
iny ;#1
lda (z80_hl),y ; fetch value from table.
sta z80_d
iny ;#2
lda (z80_hl),y ; fetch value from table.
sta z80_c
iny ;#3
lda (z80_hl),y ; fetch value from table.
sta z80_b
lda z80_l ; add 4 to hl to advance pointer
clc
adc #4
sta z80_l
bcc :+
inc z80_h
:
ldy #2
lda (z80_ix),y ; y coordinate in hl.
clc
adc z80_c ; add cosine lb
sta (z80_ix),y ; store new coordinate lb.
iny
lda (z80_ix),y
adc z80_b ; add cosine lb
sta (z80_ix),y ; store new coordinate hb.
...
The 6502 code from the shrapnel routine looks like it can be optimized as shown below. Instead of incrementing z80_hl for every byte, use different y offsets, and then update z80_hl once. The comparison is a little less lopsided with this change.
;----------------------------------------------------
; Explosion shrapnel.
;----------------------------------------------------
shrap:
ldy #1
lda (z80_ix),y ; get the angle.
clc
adc #<shrsin ; shrapnel sine table.
sta z80_l
lda #>shrsin
adc #0
sta z80_h
ldy #0
lda (z80_hl),y ; fetch value from table.
sta z80_e
iny ;#1
lda (z80_hl),y ; fetch value from table.
sta z80_d
iny ;#2
lda (z80_hl),y ; fetch value from table.
sta z80_c
iny ;#3
lda (z80_hl),y ; fetch value from table.
sta z80_b
lda z80_l ; add 4 to hl to advance pointer
clc
adc #4
sta z80_l
bcc :+
inc z80_h
:
ldy #2
lda (z80_ix),y ; y coordinate in hl.
clc
adc z80_c ; add cosine lb
sta (z80_ix),y ; store new coordinate lb.
iny
lda (z80_ix),y
adc z80_b ; add cosine lb
sta (z80_ix),y ; store new coordinate hb.
...
AGD porting notes (what is required to port AGD to a new system)
When asked if there is a guide to porting AGD to a new system, this was Kees van Oss's response on facebook:
Not really ... but this is how MPAGD works and what needs to be done to port it:
1. You start with an ASCII AGD file with commands to define graphics and the game behaviour. This AGD file can be created by converting an existing AGD4.7 game or create one with AGDX Studio or Jonathan Cauldwells WinAGD program.
2. The next step is to compile this ASCII AGD file into an assembler source file. The compiler converts all ASCII AGD commands into assembler code and adds the engine to the assembler sourcefile.
The engine is a library with routines which are called by the assembler code linked to the AGD commands.
3. After compiling, you need to assemble the assembler file into a binary file ready to run on the designed system. This assembler creates a tape or diskfile which can be used by the emulator.
4. After creating the tape or disk files, an emulator is called with the created tape or diskfile to test the game. So what needs to be changed to port MPAGD are:
- The converter, a C program (Step 1)
- The compiler, a C program (Step 2)
- The engine, a Z80 assembler file (Step 2)
You can use an existing assembler and emulator program to complete steps 3 and 4.
Things that need to be defined for a platform are:
- memory map definition
- screen handling
- sound handling
- keyboard handling
All blocks, sprites and objects are software handled by peeking and poking into screen memory so there is no hardware sprite handling except the MSX port which handles hardware sprites. The screen is based upon the ZX Spectrum, 256x192 pixels. The Spectrum has 16 colours with the limitation of a 8x8 block with 2 colours
- Blocks (tiles) are 8x8 pixels, max 255
- Sprites are 16x16 pixels, max 12
- Objects are 16x16 pixels, max 255
All these specs can be changed but all AGD4.7 games are based upon these specs.
Are you planning to port MPAGD to another platform because we have a Developers environment where you can discuss your porting problems.
Not really ... but this is how MPAGD works and what needs to be done to port it:
1. You start with an ASCII AGD file with commands to define graphics and the game behaviour. This AGD file can be created by converting an existing AGD4.7 game or create one with AGDX Studio or Jonathan Cauldwells WinAGD program.
2. The next step is to compile this ASCII AGD file into an assembler source file. The compiler converts all ASCII AGD commands into assembler code and adds the engine to the assembler sourcefile.
The engine is a library with routines which are called by the assembler code linked to the AGD commands.
3. After compiling, you need to assemble the assembler file into a binary file ready to run on the designed system. This assembler creates a tape or diskfile which can be used by the emulator.
4. After creating the tape or disk files, an emulator is called with the created tape or diskfile to test the game. So what needs to be changed to port MPAGD are:
- The converter, a C program (Step 1)
- The compiler, a C program (Step 2)
- The engine, a Z80 assembler file (Step 2)
You can use an existing assembler and emulator program to complete steps 3 and 4.
Things that need to be defined for a platform are:
- memory map definition
- screen handling
- sound handling
- keyboard handling
All blocks, sprites and objects are software handled by peeking and poking into screen memory so there is no hardware sprite handling except the MSX port which handles hardware sprites. The screen is based upon the ZX Spectrum, 256x192 pixels. The Spectrum has 16 colours with the limitation of a 8x8 block with 2 colours
- Blocks (tiles) are 8x8 pixels, max 255
- Sprites are 16x16 pixels, max 12
- Objects are 16x16 pixels, max 255
All these specs can be changed but all AGD4.7 games are based upon these specs.
Are you planning to port MPAGD to another platform because we have a Developers environment where you can discuss your porting problems.
Thursday, February 27, 2020
several thousand lines later...
A lot of progress has been made, but... is it a bad thing for a game engine not to call functions like "shoot"? I have a feeling I'll be looking at the original Z80 code. On the bright side, I'm nearing the half way point converting the code.
The engine would be faster if the data structures stored X, and Y coordinates next to each other. But I can't fix that since the game design tool would need rewritten.
The engine would be faster if the data structures stored X, and Y coordinates next to each other. But I can't fix that since the game design tool would need rewritten.
Subscribe to:
Posts (Atom)