Skip to content

Commit

Permalink
Hotfix for 80286 compatibility
Browse files Browse the repository at this point in the history
Reconfigure a few instructions, including replacing a conditional near jump with an 80286-compatible equivalent. Also updated the file standard, but none of that takes effect quite yet.
  • Loading branch information
maxotaku11niku committed Feb 20, 2023
1 parent 1a5b438 commit a0956d4
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 27 deletions.
53 changes: 35 additions & 18 deletions 98video.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
Video codec notes
.98V video codec specification
Header:
0x00 "98v"
0x00 "98V"
0x03 uint8 framerate (number of GPU frames to skip for every video frame)
0x04 uint32 number of frames
0x08 low byte uint8 Sample rate spec
0x08 low byte uint8
86 sample rate spec (bit 0-2)
0x00 44100 Hz
0x01 33075 Hz
0x02 22050 Hz
0x03 16537.5 Hz
0x04 11025 Hz
0x05 8270 Hz
0x05 8268.75 Hz
0x06 5520 Hz
0x07 4130 Hz
high byte uint8 Sample depth spec
0x00 16-bits
0x40 8-bits
0x0A uint4[16][3] colour table (rg br gb ...) for all 16 colours
Audio type spec (bit 3)
0x00 ADPCM (with buzzer compat option)
0x08 Buzzer audio
Screen resolution spec (bit 4)
0x00 640x400 (pixel aspect 1:1)
0x10 640x200 (pixel aspect 1:2)
Unused (bit 5-7)
high byte uint8 Unused
0x0A uint4[16][3] colour table (rg br gb ...) for all 16 initial colours

Frame Data:
Audio Data:
uint16 length of audio data (16-bit words)
Then a bunch of 16-bit words containing the audio data for this frame
0x00 uint16 length of audio data (16-bit words, n)
0x02 uint16[n] Audio data
ADPCM:
The audio data is in 8-bit signed ADPCM format which expands to signed 16-bit PCM
Buzzer audio:
The audio data is in 8-bit pulse widths that can be pushed to the buzzer audio control after a shift if necessary
ADPCM codec:
Encodes the difference from the last sample, and applies a bitshift according to the last difference.
The first sample is 0x0000, and the initial bitshift is 0. The bitshift value can reach a maximum of 8.
Uses two-complement signed format. The sign is figured out with test data, 0x80, and if it is negative, then abs(data) is not(data) (this is off by one but it doesn't matter).
abs(data) <= 0x18: decrement bitshift by 1 after this sample.
abs(data) >= 0x68: increment bitshift by 1 after this sample.
(My decoder actually uses an acceleration table it creates at startup just to speed things up by using an acceptable amount of memory)
Video Frame Header:
0x00 low byte 0000 IRGB planes to update (automatically determines how many plane sections and which planes they correspond to)
high byte 0000 0000
0x00 low byte UUUU IRGB planes to update (automatically determines how many plane sections and which planes they correspond to, U is reserved for 256 colour board compatibility)
high byte 0000 000P update palette?
0x02 uint4[16][3] colour table (rg br gb ...) for all 16 colours if palette is to be updated this frame, otherwise not included
Plane Header:
0x00 uint16 total length of data for this plane
Plane data chunk:
0x02 uint16 offset in plane to update (highest bit determines data type: 0 -> copy data, 1 -> fill data
Fill section:
0x00 uint16 number of fills (n)
Plane data chunk (n repetitions):
0x02 uint16 offset in plane to update
0x04 uint16 length to update (in 16-bit words)
0x06 Plane data:
16-bit words containing data for the plane (copy)
or
Single 16-bit word containing the data to fill with (fill)
0x06 uint16 Single 16-bit word containing the data to fill with
(repeats as many times as necessary)
Copy section:
0x00 uint16 number of copies (n)
Plane data chunk (n repetitions):
0x02 uint16 offset in plane to update
0x04 uint16 length to update (in 16-bit words, m)
0x06 uint16[m] 16-bit words containing data for the plane
(repeats as many times as necessary)
53 changes: 44 additions & 9 deletions src/98videoplayer.asm
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ video_read_magicnum_loop: #Check that the file signature is ok
test ah, ah
jz video_read_end_magicnum
xor ah, al
jnz video_read_wrongformat
jz video_read_stillrightformat
jmp video_read_wrongformat #Prevent generating a conditional near jump, which is unsupported below 80386
video_read_stillrightformat:
inc si
inc di
jmp video_read_magicnum_loop
Expand Down Expand Up @@ -484,8 +486,8 @@ PROCEDURE_buzzer_interrupt: #void buzzer_interrupt(void)
mov dx, 0x3FDB
mov si, cs:currentreadsample
push cs
pop ds
mov ax, cs
mov ds, ax
lodsw
out dx, al
xchg al, ah
Expand Down Expand Up @@ -577,6 +579,8 @@ PROCEDURE_frameloop: #void frameloop(void)
mov di, cs:samplebufferptr
push cs
pop es
mov ax, cs:samplebufferptr
mov cs:currentreadsample, ax
mov dx, 0xA46C
mov cx, cs:adpcmshiftval
frameloop_buzaudio_pushloop:
Expand Down Expand Up @@ -613,13 +617,11 @@ frameloop_buzaudio_pushloop:
sar ax, cl
xchg ch, cl
xor ch, ch
add ax, cs:current_sample_midpoint1
add ax, cs:current_sample_midpoint2
stosw #store sample in buffer
mov cl, cs:[bx+accelerationtable_adpcm]
dec bp
jnz frameloop_buzaudio_pushloop
mov ax, cs:samplebufferptr
mov cs:currentreadsample, ax
jmp frameloop_videodata_process
frameloop_86audio:
Expand Down Expand Up @@ -687,6 +689,39 @@ frameloop_planereadloop:
shl ax, 1
call PROCEDURE_tryreadsection
#Write data fills
#mov si, cs:filebuffercurpos
#mov ax, cs:[planeseg+bx]
#mov es, ax
#lodsw #ax has number of fills
#test ax, ax
#jz frameloop_copystart #If length is zero, skip to doing copies
#mov dx, ax
#frameloop_fillloop:
#lodsw #ax has offset
#mov di, ax
#lodsw #ax has length
#mov cx, ax
#lodsw #ax has word to copy
#rep stosw
#dec dx
#jnz frameloop_fillloop
#Write data copies
#frameloop_copystart:
#lodsw #ax has number of copies
#test ax, ax
#jz frameloop_planeend #If length is zero, skip to the end of the plane
#mov dx, ax
#frameloop_copyloop:
#lodsw #ax has offset
#mov di, ax
#lodsw #ax has length
#mov cx, ax
#rep movsw
#dec dx
#jnz frameloop_copyloop
#Write data to planes
mov si, cs:filebuffercurpos
mov dx, cs:[videolen+bx]
Expand All @@ -702,7 +737,7 @@ frameloop_deltaloop:
jnz frameloop_filldelta
lodsw #ax has length
mov cx, ax
sub dx, cx
sub dx, ax
rep movsw #copy time
sub dx, 2
ja frameloop_deltaloop
Expand Down Expand Up @@ -736,8 +771,8 @@ frameloop_planeend:
#Hz 44100.0 33075.0 22050.0 16537.5 11025.0 8268.8 5520.0 4130.0
sampleratespec_to_buzzfreq: .word 0x0038, 0x004A, 0x006F, 0x0095, 0x00DF, 0x0129, 0x01BD, 0x0253 #2.4576 MHz bus
.word 0x002D, 0x003C, 0x005B, 0x0079, 0x00B5, 0x00F1, 0x016A, 0x01E3 #1.9968 MHz bus
shiftdownvalues: .byte 0x0A, 0x0A, 0x09, 0x09, 0x08, 0x08, 0x07, 0x07 #2.4576 MHz bus
.byte 0x0B, 0x0A, 0x0A, 0x09, 0x09, 0x08, 0x08, 0x07 #1.9968 MHz bus
shiftdownvalues: .byte 0x0B, 0x0A, 0x0A, 0x09, 0x09, 0x08, 0x08, 0x07 #2.4576 MHz bus
.byte 0x0B, 0x0B, 0x0A, 0x0A, 0x09, 0x09, 0x08, 0x08 #1.9968 MHz bus
old_vsync_vector_offset: .word 0x0000
old_vsync_vector_segment: .word 0x0000
old_timer_vector_offset: .word 0x0000
Expand Down

0 comments on commit a0956d4

Please sign in to comment.