Porting Wolfenstein 3D to Mac OS X
We need the following functions converted to c code for the game to run,
(also I have 24 errors, and slowly getting rid of them, once this file is done and this assembly code is converted it should build, startup and knowing programming probably crash..
)
Its just 5 functions that were written in assembly to make the rendering faster.
(also I have 24 errors, and slowly getting rid of them, once this file is done and this assembly code is converted it should build, startup and knowing programming probably crash..
)Its just 5 functions that were written in assembly to make the rendering faster.
Code:
;
; Assembly language functions for wolf 3-D PPC version
; Written by Bill Heineman
; 9-12-94 (Rev for removing scalers and using direct code)
;
;
; Bullshit to make the PPC Mac environment know I'm here
;
import VideoWidth ; global variable from C program
import MacViewHeight
import ArtData
import VideoPointer
import ScaleDiv
toc
tc VideoWidth[TC],VideoWidth
tc MacViewHeight[TC],MacViewHeight
tc ArtData[TC],ArtData
tc VideoPointer[TC],VideoPointer
tc ScaleDiv[TC],ScaleDiv
export IO_ScaleWallColumn[DS]
export .IO_ScaleWallColumn[PR]
export SpriteGlue[DS]
export .SpriteGlue[PR]
toc ;Table of contents for the subroutines
tc IO_ScaleWallColumn[TC], IO_ScaleWallColumn[DS]
tc SpriteGlue[TC], SpriteGlue[DS]
csect IO_ScaleWallColumn[DS]
dc.l .IO_ScaleWallColumn[PR]
dc.l TOC[tc0]
csect SpriteGlue[DS]
dc.l .SpriteGlue[PR]
dc.l TOC[tc0]
;
; This routine will draw a scaled wall column.
;
; void IO_ScaleWallColumn(Word x,Word scale,LongWord column)
;
WALLHEIGHT EQU 128+1
; Passed from "C"
X equ R3 ;X coord
Scale equ R4 ;Scale factor
Tile equ R5 ;Tile to draw
Column equ R6 ;Packed wall column #
; Locals
ArtStart EQU R7 ;Pointer to wall art
ScreenPtr EQU R8 ;Pointer to screen memory column
Frac EQU R9 ;Fractional scaler
Integer EQU R10 ;Fractional integer
VWidth EQU R11 ;Video of the video screen in bytes
Delta EQU R6 ;Delta factor and temp
VHeight EQU R12 ;Height of mac screen
Temp EQU R3 ;Temp (Use AFTER X is added)
csect .IO_ScaleWallColumn[PR]
CMPLWI Scale,0 ;Is the scale factor zero?
BEQLR ;Exit NOW!
LWZ ScreenPtr,VideoPointer[TC](RTOC) ;Get handle to video
LWZ ArtStart,ArtData[TC](RTOC) ;Get handle to art data list
LWZ VWidth,VideoWidth[TC](RTOC) ;Get handle to video width
LWZ Frac,ScaleDiv[TC](RTOC)
LWZ VHeight,MacViewHeight[TC](RTOC) ;Get pointer to view height
LWZ ScreenPtr,0(ScreenPtr) ;I have the base pointer
LWZ VWidth,0(VWidth) ;Init video width
LWZ VHeight,0(VHeight) ;Get the number of lines visible
SLWI Scale,Scale,1 ;Mul scale by 2 (Get true pixel value
ADD ScreenPtr,ScreenPtr,X ;Add the X coord (Frees Temp)
SLWI Temp,Scale,1 ;Get low word index
SLWI Tile,Tile,2 ;Get the wall shape pointer
LWZX Frac,Frac,Temp ;Get the scale factor
SLWI Column,Column,7 ;Mul by 128 pixels
LWZX ArtStart,ArtStart,Tile ;Get pointer to the shape
ADD ArtStart,ArtStart,Column ;I have the shape ptr
CMPLW Scale,VHeight ;Too big?
BGE ClipTop ;Clip the top
;
; No clipping needed!
; Adjust the dest screen for the starting Y coord
;
MTCTR Scale ;Init counter
SUB Temp,VHeight,Scale ;How many lines to jump down?
LI Delta,0 ;Init the delta factor
SRWI Temp,Temp,1 ;Divide by to center vertically
SRWI Integer,Frac,24 ;Isolate the integer
MULLW Temp,VWidth,Temp ;Adjust the Y coord
SLWI Frac,Frac,8 ;Isolate the fraction
ADD ScreenPtr,ScreenPtr,Temp ;Create the dest screen pointer
;
; Tight loop
; Grab byte, adjust fractional scaler values and store to screen
;
More:
LBZ R0,0(ArtStart) ;Fetch a shape byte
ADDC. Delta,Delta,Frac ;Add the scaler fractional
STB R0,0(ScreenPtr) ;Store on the screen
ADDE ArtStart,ArtStart,Integer ;Add the constant
ADD ScreenPtr,ScreenPtr,VWidth ;Go down a line
BDNZ More ;All lines done?
BLR ;Exit routine
;
; Clip the top and bottom
; Calc the number of lost lines by clipping and "Fake"
; the numbers as if I processed those missing lines
;
ClipTop:
MTCTR VHeight ;I will draw a screen line full
SUB Temp,Scale,VHeight ;How many lines to jump down?
SRWI Integer,Frac,24 ;Isolate the integer
SRWI Temp,Temp,1 ;Divide by to center vertically
MULLW Temp,Frac,Temp ;Adjust the scaler by lost lines
SRWI Delta,Temp,24 ;How many bytes are lost?
ADD ArtStart,ArtStart,Delta ;Create the SOURCE art pointer
SLWI Frac,Frac,8 ;Isolate the fraction
SLWI Delta,Temp,8 ;Init the adjusted delta
B More ;Jump to the code
;
; Call the compiled scaler to draw a run of the line
;
csect .SpriteGlue[PR]
SGArtStart EQU R3 ;Pointer to the 6 byte run structure
SGFrac EQU R4 ;Pointer to the scaler
SGInteger EQU R5 ;Pointer to the video
SGScreenPtr EQU R6 ;Pointer to the run base address
SGCount EQU R7
SGDelta EQU R8
SGVWidth EQU R9
LWZ SGVWidth,VideoWidth[TC](RTOC)
LWZ SGVWidth,0(SGVWidth)
MTCTR SGCount
SMore:
LBZ R0,0(SGArtStart) ;Fetch a shape byte
ADDC. SGDelta,SGDelta,SGFrac ;Add the scaler fractional
STB R0,0(SGScreenPtr) ;Store on the screen
ADDE SGArtStart,SGArtStart,SGInteger ;Add the constant
ADD SGScreenPtr,SGScreenPtr,SGVWidth ;Go down a line
BDNZ SMore ;All lines done?
BLR ;Exit routineSir, e^iπ + 1 = 0, hence God exists; reply!
Quote: Da: Axel Wefers
Oggetto: Re: Wolfenstein 3-D
Data: 15 novembre 2005 0:34:40 GMT+01:00
A: (hidden)
On 14 Nov 2005, at 16:54, Francesco Valeri wrote:
Hello,
We are currently discussing porting Wolfenstein 3-D to Mac OS X. We know you actually did it in the past, so perhaps you could help us with the rendering engine.
A discussion is currently taking place here:
http://www.idevgames.com/forum/showthread.php?t=10669
Thanks in advance,
Francesco
Hi,
I didn't port it using xCode (or ProjectBuilder). I did use CodeWarrior and "carbonized" the source.
Nowadays it seems more sensible to use xCode because CodeWarrior is going to stop their mac support and it seems to be a good idea to remove any PPC asm code since the Intel machines are around the corner.
I had a quick look at your forum thread: It seems that your only problem is the PPC asm code. It is rather trivial and you should be able to convert it very quickly to C code. If you are not familiar with PPC asm I would suggest that you have a look at IBM's online PPC assembler language reference located at: http://publibn.boulder.ibm.com/doc_link/...ref373.htm
Don't hesitate to ask if there are more questions,
Axel
PS: It's Rebecca Heineman who did do the original SNES/Apple IIe/Mac port. She is transgendered.
...
...
...
This is good news, looks like we might manage to get this running In the near futre, I do hope so!
Sir, e^iπ + 1 = 0, hence God exists; reply!
http://fax.xmgfree.com/Wolf3D.zip
(thanks for hosting this sixteyfive!)
Ive fixed all the errors I can as yet, I still get a bunch of warnings about SetPort though, the current errors are undefined types:
SFTypeList MyList = {'SAVE'};
SFReply Reply;
and
AppFile Stuff;
Anyone know what files I need to include to get these or what equivelant I should use for Carbon?
once these errors are fixed, there are no more in the rest of the files so It should startup or load maybe.
If anyone could shed some light on the warnings that would be most appreciated, because I dont know if they are acceptable warnings or will cause problems when the programs running.
(thanks for hosting this sixteyfive!)
Ive fixed all the errors I can as yet, I still get a bunch of warnings about SetPort though, the current errors are undefined types:
SFTypeList MyList = {'SAVE'};
SFReply Reply;
and
AppFile Stuff;
Anyone know what files I need to include to get these or what equivelant I should use for Carbon?
once these errors are fixed, there are no more in the rest of the files so It should startup or load maybe.
If anyone could shed some light on the warnings that would be most appreciated, because I dont know if they are acceptable warnings or will cause problems when the programs running.
Sir, e^iπ + 1 = 0, hence God exists; reply!
Apart from the SFTypeList and SFReply and stuff, im trying to fix the warnings too. I think that because the API has changed somewhat that I need to try and fix the warnings..
Im fixing warnings like
Passing arg 1 of ']ShowWindow' from incompatable pointer type.
Passing arg 1 of 'SetPort' from incompatable pointer type.
by explicit casting, but is that the right thing to do. I dont know if this is going to cause errors later?
ShowWindow(MyDialog); /* Display with OK button framed */
to
ShowWindow((WindowRef)MyDialog);
SetPort((WindowPtr) MyDialog);
to
SetPort((GrafPtr) MyDialog);
is this right, can I assume that if theres no warnings its going to work?
edit: also doesn anyone know about the SFType list stuff, is there a replacement I should use or what, because once thats done this will build, and all I need is to fix the assembly code then whatever bugs crop up.
Im fixing warnings like
Passing arg 1 of ']ShowWindow' from incompatable pointer type.
Passing arg 1 of 'SetPort' from incompatable pointer type.
by explicit casting, but is that the right thing to do. I dont know if this is going to cause errors later?
ShowWindow(MyDialog); /* Display with OK button framed */
to
ShowWindow((WindowRef)MyDialog);
SetPort((WindowPtr) MyDialog);
to
SetPort((GrafPtr) MyDialog);
is this right, can I assume that if theres no warnings its going to work?
edit: also doesn anyone know about the SFType list stuff, is there a replacement I should use or what, because once thats done this will build, and all I need is to fix the assembly code then whatever bugs crop up.
Sir, e^iπ + 1 = 0, hence God exists; reply!
unknown Wrote:edit: also doesn anyone know about the SFType list stuff, is there a replacement I should use or what, because once thats done this will build, and all I need is to fix the assembly code then whatever bugs crop up.
My MacToolbox is a bit rusty, but SF is the Standard Filemanager you had back in pre OS 9. The Carbon version are the Navigation Services, so you'll need to replace all the SF calls to Navigation Services calls.
Maybe someone knows of a better way though..
"When you dream, there are no rules..."
Ill give that a shot, thanks Taxxodium.
Sir, e^iπ + 1 = 0, hence God exists; reply!
I commented out the save and load game functionality and now it builds except there are a lot of functiont like
all of those, Is there a replacement for them?
For InitGraf for example the quickdraw documentation has this:
Code:
//MaxApplZone(); /* Expand the heap so code segments load at the top */
//InitGraf((Ptr) &qd_thePort); /* Init the graphics system */
//InitFonts(); /* Init the font manager */
//InitWindows(); /* Init the window manager */
//InitMenus(); /* Init the menu manager */
//TEInit(); /* Init text edit */
//InitDialogs(nil); /* Init the dialog manager */all of those, Is there a replacement for them?
For InitGraf for example the quickdraw documentation has this:
Code:
/*
* InitGraf()
*
* Availability:
* Mac OS X: not available
* CarbonLib: not available
* Non-Carbon CFM: in InterfaceLib 7.1 and later
*/Sir, e^iπ + 1 = 0, hence God exists; reply!
Good idea, this build on my computer but has save functionality taken out.
May need alterations for another os.
http://fax.xmgfree.com/Wolf3D.zip
May need alterations for another os.
http://fax.xmgfree.com/Wolf3D.zip
Sir, e^iπ + 1 = 0, hence God exists; reply!
Maybe, just maybe, we can separate the engine code from the mac specific code. The mac code can then be replaced with Cocoa code to add save functionality.
"When you dream, there are no rules..."
Yeah that would be good, If this goes well I might try and port it to opengl but thats probably going to be much more difficult than im thinking just now, hopefully though.
sixteyfive: It just crashes.
sixteyfive: It just crashes.
Sir, e^iπ + 1 = 0, hence God exists; reply!

